class Array
def to_formatted_s(format = :default)
output:
Adding in the :db argument as the format yields a prettier
Blog.find(:all).to_formatted_s # => "First PostSecond PostThird Post"
to_s on all elements and joining them:
Converts a collection of elements into a formatted string by calling
def to_formatted_s(format = :default) case format when :db if respond_to?(:empty?) && self.empty? "null" else collect { |element| element.id }.join(",") end else to_default_s end end