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 end
def delete_if(&block) def delete_if(&block)
self.each { |k,v| self.each do |k,v|
if yield k, v if yield k, v
delete(k) delete(k)
end end
} end
end end
def reject(&block) def reject(&block)
@ -139,7 +139,14 @@ module BSON
end end
def reject!(&block) 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 end
def clear def clear

View File

@ -189,7 +189,8 @@ class OrderedHashTest < Test::Unit::TestCase
def test_reject_bang def test_reject_bang
@oh.reject! { |k, v| k == 'z' } @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 end
def test_clone def test_clone