Permalink
Browse files

RUBY-265 semantics should == Hash#reject!

  • Loading branch information...
1 parent d0a4483 commit af6552ed3c1035b5ccca78b5e6b414af853a36f6 @banker banker committed Apr 15, 2011
Showing with 12 additions and 4 deletions.
  1. +10 −3 lib/bson/ordered_hash.rb
  2. +2 −1 test/bson/ordered_hash_test.rb
View
@@ -125,11 +125,11 @@ def delete(key, &block)
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 @@ def reject(&block)
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
@@ -189,7 +189,8 @@ def test_reject
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

0 comments on commit af6552e

Please sign in to comment.