Permalink
Browse files

Updates documentation with cleaner examples and texts [ci skip]

  • Loading branch information...
1 parent da4252f commit 422d3a4f042df8ea4bd42b0dca38a295a218c376 @alvaropereyra alvaropereyra committed May 28, 2012
@@ -39,14 +39,27 @@ def to_sentence(options = {})
end
# Converts a collection of elements into a formatted string by calling
- # <tt>to_s</tt> on all elements and joining them:
+ # <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:
#
# Blog.all.to_formatted_s(:db) # => "1,2,3"
+
def to_formatted_s(format = :default)
case format
when :db
@@ -4,6 +4,7 @@
class BigDecimal
YAML_MAPPING = { 'Infinity' => '.Inf', '-Infinity' => '-.Inf', 'NaN' => '.NaN' }
+
def encode_with(coder)
string = to_s
coder.represent_scalar(nil, YAML_MAPPING[string] || string)

0 comments on commit 422d3a4

Please sign in to comment.