Enumerable#find_all return Enumerator if non block given

This commit is contained in:
ksss
2014-03-17 23:31:15 +09:00
parent 2f8dbd8e5d
commit fd80d4ecdd
2 changed files with 6 additions and 0 deletions
@@ -448,6 +448,10 @@ assert 'Enumerable#map' do
assert_equal [[1,0],[4,1],[9,4]], c
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
a = [1,2,3]
b = a.each_index
+2
View File
@@ -144,6 +144,8 @@ module Enumerable
#
# ISO 15.3.2.2.8
def find_all(&block)
return to_enum :find_all unless block_given?
ary = []
self.each{|*val|
ary.push(val.__svalue) if block.call(*val)