Skip to content

Commit

Permalink
Hash#{reject,reject!} fix yield value
Browse files Browse the repository at this point in the history
  • Loading branch information
ksss committed Mar 23, 2014
1 parent d8fc05f commit d9068f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions mrbgems/mruby-enumerator/test/enumerator.rb
Expand Up @@ -508,6 +508,20 @@ def (o = Object.new).each
assert_equal({3=>4}, h)
end

assert 'Hash#reject' do
h = {1=>2,3=>4,5=>6}
hret = h.reject.with_index {|a,b| a[1] == 4}
assert_equal({1=>2,5=>6}, hret)
assert_equal({1=>2,3=>4,5=>6}, h)
end

assert 'Hash#reject!' do
h = {1=>2,3=>4,5=>6}
hret = h.reject!.with_index {|a,b| a[1] == 4}
assert_equal h, hret
assert_equal({1=>2,5=>6}, h)
end

assert 'Range#each' do
a = (1..5)
b = a.each
Expand Down
4 changes: 2 additions & 2 deletions mrblib/hash.rb
Expand Up @@ -139,7 +139,7 @@ def reject!(&b)
keys = []
self.each_key{|k|
v = self[k]
if b.call(k, v)
if b.call([k, v])
keys.push(k)
end
}
Expand All @@ -157,7 +157,7 @@ def reject(&b)
h = {}
self.each_key{|k|
v = self[k]
unless b.call(k, v)
unless b.call([k, v])
h[k] = v
end
}
Expand Down

0 comments on commit d9068f0

Please sign in to comment.