aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/core_ext/array.rb6
-rw-r--r--activesupport/test/core_ext/array_ext_test.rb3
3 files changed, 9 insertions, 2 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index a651cff958..670584b8eb 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Make Array#in_groups_of just return the grouped collection if a block isn't given. [Marcel Molina Jr.]
+
* Don't destroy a HashWithIndifferentAccess if symbolize_keys! or stringify_keys! is called on it. Closes #5076. [Marcel Molina Jr., guy.naor@famundo.com]
* Document Module::delegate. #5002 [pergesu@gmail.com]
diff --git a/activesupport/lib/active_support/core_ext/array.rb b/activesupport/lib/active_support/core_ext/array.rb
index db6f5587da..243aeab423 100644
--- a/activesupport/lib/active_support/core_ext/array.rb
+++ b/activesupport/lib/active_support/core_ext/array.rb
@@ -16,7 +16,11 @@ class Array #:nodoc:
require 'enumerator'
collection = dup
collection << fill_with until collection.size.modulo(number).zero?
- collection.each_slice(number, &block)
+ grouped_collection = [] unless block_given?
+ collection.each_slice(number) do |group|
+ block_given? ? yield(group) : grouped_collection << group
+ end
+ grouped_collection unless block_given?
end
# Divide the array into one or more subarrays based on a delimiting +value+
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb
index caf3af2345..0d5f58a9be 100644
--- a/activesupport/test/core_ext/array_ext_test.rb
+++ b/activesupport/test/core_ext/array_ext_test.rb
@@ -47,6 +47,7 @@ class ArrayExtGroupingTests < Test::Unit::TestCase
end
assert_equal [%w(a b c), %w(d e f), %w(g h i)], groups
+ assert_equal [%w(a b c), %w(d e f), %w(g h i)], ('a'..'i').to_a.in_groups_of(3)
end
def test_group_by_with_padding
@@ -122,4 +123,4 @@ class ArrayToXmlTests < Test::Unit::TestCase
assert xml.include?(%(<street-address>Evergreen</street-address>))
assert xml.include?(%(<name>Jason</name>))
end
-end \ No newline at end of file
+end