Commit 31b2980a authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #1880 from ksss/enum-each_with_index

Enumrable#each_with_index return Enumerator if non block given
parents 555c1876 9abe4135
......@@ -438,6 +438,10 @@ assert 'Integral#times' do
assert_equal [0,1,2], c
end
assert 'Enumerable#each_with_index' do
assert_equal [['a',0],['b',1],['c',2]], ['a','b','c'].each_with_index.to_a
end
assert 'Enumerable#map' do
a = [1,2,3]
b = a.map
......
......@@ -108,6 +108,8 @@ module Enumerable
#
# ISO 15.3.2.2.5
def each_with_index(&block)
return to_enum :each_with_index unless block_given?
i = 0
self.each{|*val|
block.call(val.__svalue, i)
......
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