diff options
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/array/conversions.rb | 2 | ||||
-rw-r--r-- | activesupport/test/core_ext/array_ext_test.rb | 4 |
3 files changed, 8 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 0ed194591c..609d56ff68 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed that Array#to_sentence will return "" on an empty array instead of ", and" #3842, #4031 [rubyonrails@beautifulpixel.com] + * Add Enumerable#group_by for grouping collections based on the result of some block. Useful, for example, for grouping records by date. diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index bfa92c3031..46962ded1b 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -11,6 +11,8 @@ module ActiveSupport #:nodoc: options.reverse_merge! :connector => 'and', :skip_last_comma => false case length + when 0 + "" when 1 self[0] when 2 diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 9e23eed450..6a946064fc 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -15,7 +15,11 @@ end class ArrayExtConversionTests < Test::Unit::TestCase def test_plain_array_to_sentence + assert_equal "", [].to_sentence + assert_equal "one", ['one'].to_sentence + assert_equal "one and two", ['one', 'two'].to_sentence assert_equal "one, two, and three", ['one', 'two', 'three'].to_sentence + end def test_to_sentence_with_connector |