From 422d3a4f042df8ea4bd42b0dca38a295a218c376 Mon Sep 17 00:00:00 2001 From: Alvaro Pereyra Date: Mon, 28 May 2012 02:25:05 -0500 Subject: Updates documentation with cleaner examples and texts [ci skip] --- .../lib/active_support/core_ext/array/conversions.rb | 15 ++++++++++++++- .../active_support/core_ext/big_decimal/conversions.rb | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') 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 - # to_s on all elements and joining them: + # to_s 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"] + # + # + # to_formatted_s 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) -- cgit v1.2.3