Permalink
Browse files

AS guide: documents key-based interpolation

  • Loading branch information...
1 parent 4d0df0a commit 8458abb5e52dc38daa8176ed39d9dc45aa98f261 @fxn fxn committed Aug 23, 2009
Showing with 13 additions and 0 deletions.
  1. +13 −0 railties/guides/source/active_support_overview.textile
@@ -692,6 +692,19 @@ The method +String#squish+ strips leading and trailing whitespace, and substitut
There's also the destructive version +String#squish!+.
+h4. Key-based Interpolation
+
+In Ruby 1.9 the <tt>%</tt> string operator supports key-based interpolation, both formatted and unformatted:
+
+<ruby>
+"Total is %<total>.02f" % {:total => 43.1} # => Total is 43.10
+"I say %{foo}" % {:foo => "wadus"} # => "I say wadus"
+"I say %{woo}" % {:foo => "wadus"} # => KeyError
+</ruby>
+
+Active Support adds that functionality to <tt>%</tt> in previous versions of Ruby.
+
+
h3. Extensions to +Numeric+
...

0 comments on commit 8458abb

Please sign in to comment.