Commit 2bf718fa authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #1882 from ksss/enum-find_all

Enumerable#find_all return Enumerator if non block given
parents d9107fd1 fd80d4ec
...@@ -452,6 +452,10 @@ assert 'Enumerable#map' do ...@@ -452,6 +452,10 @@ assert 'Enumerable#map' do
assert_equal [[1,0],[4,1],[9,4]], c assert_equal [[1,0],[4,1],[9,4]], c
end end
assert 'Enumerable#find_all' do
assert_equal [[3,4]], [[1,2],[3,4],[5,6]].find_all.each{ |i| i[1] == 4 }
end
assert 'Array#each_index' do assert 'Array#each_index' do
a = [1,2,3] a = [1,2,3]
b = a.each_index b = a.each_index
......
...@@ -146,6 +146,8 @@ module Enumerable ...@@ -146,6 +146,8 @@ module Enumerable
# #
# ISO 15.3.2.2.8 # ISO 15.3.2.2.8
def find_all(&block) def find_all(&block)
return to_enum :find_all unless block_given?
ary = [] ary = []
self.each{|*val| self.each{|*val|
ary.push(val.__svalue) if block.call(*val) ary.push(val.__svalue) if block.call(*val)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment