Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

RUBY-265 semantics should == Hash#reject!

  • Loading branch information...
commit af6552ed3c1035b5ccca78b5e6b414af853a36f6 1 parent d0a4483
@banker banker authored
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
13 lib/bson/ordered_hash.rb
@@ -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
View
3  test/bson/ordered_hash_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.