RUBY-265 semantics should == Hash#reject!

This commit is contained in:
Kyle Banker 2011-04-15 16:19:00 -04:00
parent d0a4483713
commit af6552ed3c
2 changed files with 12 additions and 4 deletions

View File

@ -125,11 +125,11 @@ module BSON
end
def delete_if(&block)
self.each { |k,v|
self.each do |k,v|
if yield k, v
delete(k)
end
}
end
end
def reject(&block)
@ -139,7 +139,14 @@ module BSON
end
def reject!(&block)
delete_if(&block)
changed = false
self.each do |k,v|
if yield k, v
changed = true
delete(k)
end
end
changed ? self : nil
end
def clear

View File

@ -189,7 +189,8 @@ class OrderedHashTest < Test::Unit::TestCase
def test_reject_bang
@oh.reject! { |k, v| k == 'z' }
assert !@ok.keys.include?('z')
assert !@oh.keys.include?('z')
assert_nil @oh.reject! { |k, v| k == 'z' }
end
def test_clone