aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlvaro Pereyra <alvaro@xendacentral.com>2012-05-28 02:25:05 -0500
committerAlvaro Pereyra <alvaro@xendacentral.com>2012-05-28 02:27:23 -0500
commit422d3a4f042df8ea4bd42b0dca38a295a218c376 (patch)
tree665d54be3f808aeb154aeb3baa61460b20bf99be
parentda4252f4a16bd3166866201a852f938263a3225c (diff)
downloadrails-422d3a4f042df8ea4bd42b0dca38a295a218c376.tar.gz
rails-422d3a4f042df8ea4bd42b0dca38a295a218c376.tar.bz2
rails-422d3a4f042df8ea4bd42b0dca38a295a218c376.zip
Updates documentation with cleaner examples and texts [ci skip]
-rw-r--r--activesupport/lib/active_support/core_ext/array/conversions.rb15
-rw-r--r--activesupport/lib/active_support/core_ext/big_decimal/conversions.rb1
2 files changed, 15 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb
index 193388a158..d5735dd7eb 100644
--- a/activesupport/lib/active_support/core_ext/array/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -39,7 +39,19 @@ class Array
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"
#
@@ -47,6 +59,7 @@ class Array
# id list:
#
# Blog.all.to_formatted_s(:db) # => "1,2,3"
+
def to_formatted_s(format = :default)
case format
when :db
diff --git a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb
index 3ec7e576c8..5b673e104a 100644
--- a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb
@@ -4,6 +4,7 @@ require 'yaml'
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)