aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2009-08-30 22:18:33 +0200
committerXavier Noria <fxn@hashref.com>2009-08-30 22:18:33 +0200
commit755fd0ba8205f6a1f5b89b02301176ab5fc0b3e2 (patch)
treeb38f92da515c6eb7fea9a00d7f93cc225ff5c51b
parent0ed583f59a026965d7480345275baf803d37cd48 (diff)
downloadrails-755fd0ba8205f6a1f5b89b02301176ab5fc0b3e2.tar.gz
rails-755fd0ba8205f6a1f5b89b02301176ab5fc0b3e2.tar.bz2
rails-755fd0ba8205f6a1f5b89b02301176ab5fc0b3e2.zip
AS guide: explains Array#to_formatted_s
-rw-r--r--railties/guides/source/active_support_overview.textile14
1 files changed, 14 insertions, 0 deletions
diff --git a/railties/guides/source/active_support_overview.textile b/railties/guides/source/active_support_overview.textile
index 4f18f0c496..fb14de8852 100644
--- a/railties/guides/source/active_support_overview.textile
+++ b/railties/guides/source/active_support_overview.textile
@@ -845,6 +845,20 @@ The defaults for these options can be localised, their keys are:
Options <tt>:connector</tt> and <tt>:skip_last_comma</tt> are deprecated.
+h5. +to_formatted_s+
+
+The method +to_formatted_s+ acts like +to_s+ by default.
+
+If the array contains items that respond to +id+, however, it may be passed the symbol <tt>:db</tt> as argument. That's typically used with collections of ARs, though technically any object in Ruby 1.8 responds to +id+ indeed. Returned strings are:
+
+<ruby>
+[].to_formatted_s(:db) # => "null"
+[user].to_formatted_s(:db) # => "8456"
+invoice.lines.to_formatted_s(:db) # => "23,567,556,12"
+</ruby>
+
+Integers in the example above are supposed to come from the respective calls to +id+.
+
h4. Wrapping
The class method +Array.wrap+ behaves like the function +Array()+ except that it does not try to call +to_a+ on its argument. That changes the behaviour for enumerables: