mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Hash#{reject,reject!} fix yield value
This commit is contained in:
@@ -508,6 +508,20 @@ assert 'Hash#select!' do
|
||||
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
|
||||
|
||||
+2
-2
@@ -139,7 +139,7 @@ class Hash
|
||||
keys = []
|
||||
self.each_key{|k|
|
||||
v = self[k]
|
||||
if b.call(k, v)
|
||||
if b.call([k, v])
|
||||
keys.push(k)
|
||||
end
|
||||
}
|
||||
@@ -157,7 +157,7 @@ class Hash
|
||||
h = {}
|
||||
self.each_key{|k|
|
||||
v = self[k]
|
||||
unless b.call(k, v)
|
||||
unless b.call([k, v])
|
||||
h[k] = v
|
||||
end
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user