mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make Array#in_groups_of just return the grouped collection if a block isn't given. [Marcel Molina Jr.]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4345 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
ff96498848
commit
36d1a2f302
3 changed files with 9 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
||||||
*SVN*
|
*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]
|
* 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]
|
* Document Module::delegate. #5002 [pergesu@gmail.com]
|
||||||
|
|
|
@ -16,7 +16,11 @@ class Array #:nodoc:
|
||||||
require 'enumerator'
|
require 'enumerator'
|
||||||
collection = dup
|
collection = dup
|
||||||
collection << fill_with until collection.size.modulo(number).zero?
|
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
|
end
|
||||||
|
|
||||||
# Divide the array into one or more subarrays based on a delimiting +value+
|
# Divide the array into one or more subarrays based on a delimiting +value+
|
||||||
|
|
|
@ -47,6 +47,7 @@ class ArrayExtGroupingTests < Test::Unit::TestCase
|
||||||
end
|
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)], groups
|
||||||
|
assert_equal [%w(a b c), %w(d e f), %w(g h i)], ('a'..'i').to_a.in_groups_of(3)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_group_by_with_padding
|
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?(%(<street-address>Evergreen</street-address>))
|
||||||
assert xml.include?(%(<name>Jason</name>))
|
assert xml.include?(%(<name>Jason</name>))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue