Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed that Array#to_sentence will return "" on an empty array instead…

… of ", and" (closes #3842, #4031) [rubyonrails@beautifulpixel.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3739 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 4c5db2c7eac5fc7fe76e0c0cd12d8adf5b7ea4f1 1 parent 3574ab3
@dhh dhh authored
View
2  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.
View
2  activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -11,6 +11,8 @@ def to_sentence(options = {})
options.reverse_merge! :connector => 'and', :skip_last_comma => false
case length
+ when 0
+ ""
when 1
self[0]
when 2
View
4 activesupport/test/core_ext/array_ext_test.rb
@@ -15,7 +15,11 @@ def test_number_array
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
Please sign in to comment.
Something went wrong with that request. Please try again.