1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Array#to_formatted_s does not call each element's to_s anymore

Array#to_s calls each element's inspect since ruby 1.9
This commit is contained in:
Akira Matsuda 2013-07-11 18:13:43 +09:00
parent 3c90f7a258
commit 5ff00fcd3d

View file

@ -82,23 +82,8 @@ class Array
end
end
# Converts a collection of elements into a formatted string by calling
# <tt>to_s</tt> on all elements and joining them. Having this model:
#
# class Blog < ActiveRecord::Base
# def to_s
# title
# end
# end
#
# Blog.all.map(&:title) #=> ["First Post", "Second Post", "Third post"]
#
# <tt>to_formatted_s</tt> shows us:
#
# Blog.all.to_formatted_s # => "First PostSecond PostThird Post"
#
# Adding in the <tt>:db</tt> argument as the format yields a comma separated
# id list:
# Extends <tt>Array#to_s</tt> to convert a collection of elements into a
# comma separated id list if <tt>:db</tt> argument is given as the format.
#
# Blog.all.to_formatted_s(:db) # => "1,2,3"
def to_formatted_s(format = :default)