mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
fix return value for with_index
This commit is contained in:
@@ -156,10 +156,10 @@ class Enumerator
|
||||
return to_enum :with_index, offset unless block_given?
|
||||
raise TypeError, "no implicit conversion of #{offset.class} into Integer" unless offset.respond_to?(:to_int)
|
||||
|
||||
n = offset.to_int
|
||||
each do |i|
|
||||
yield [i,n]
|
||||
n = offset.to_int - 1
|
||||
enumerator_block_call do |i|
|
||||
n += 1
|
||||
yield [i,n]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -396,3 +396,12 @@ assert 'modifying existing methods' do
|
||||
assert_equal Enumerator, {a:1}.each.class
|
||||
assert_equal Enumerator, (1..5).each.class
|
||||
end
|
||||
|
||||
assert 'Array#map!' do
|
||||
a = [1,2,3]
|
||||
b = a.map!
|
||||
b.with_index do |i, index|
|
||||
[i*i, index*index]
|
||||
end
|
||||
assert_equal [[1,0],[4,1],[9,4]], a
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user