From 755fd0ba8205f6a1f5b89b02301176ab5fc0b3e2 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 30 Aug 2009 22:18:33 +0200 Subject: AS guide: explains Array#to_formatted_s --- railties/guides/source/active_support_overview.textile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 :connector and :skip_last_comma 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 :db 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: + + +[].to_formatted_s(:db) # => "null" +[user].to_formatted_s(:db) # => "8456" +invoice.lines.to_formatted_s(:db) # => "23,567,556,12" + + +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: -- cgit v1.2.3