Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

AS guide: documents key-based interpolation

  • Loading branch information...
commit 8458abb5e52dc38daa8176ed39d9dc45aa98f261 1 parent 4d0df0a
@fxn fxn authored
Showing with 13 additions and 0 deletions.
  1. +13 −0 railties/guides/source/active_support_overview.textile
View
13 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+
...
Please sign in to comment.
Something went wrong with that request. Please try again.