From 8458abb5e52dc38daa8176ed39d9dc45aa98f261 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 23 Aug 2009 14:09:16 +0200 Subject: AS guide: documents key-based interpolation --- railties/guides/source/active_support_overview.textile | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_support_overview.textile b/railties/guides/source/active_support_overview.textile index 5e6c2030c6..06d750afc9 100644 --- a/railties/guides/source/active_support_overview.textile +++ b/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 % string operator supports key-based interpolation, both formatted and unformatted: + + +"Total is %.02f" % {:total => 43.1} # => Total is 43.10 +"I say %{foo}" % {:foo => "wadus"} # => "I say wadus" +"I say %{woo}" % {:foo => "wadus"} # => KeyError + + +Active Support adds that functionality to % in previous versions of Ruby. + + h3. Extensions to +Numeric+ ... -- cgit v1.2.3