Fixed OrderedHash key deletion.
This commit is contained in:
parent
d3d0d5a16e
commit
5c751e9cfc
|
@ -63,6 +63,24 @@ class OrderedHash < Hash
|
|||
str << '}'
|
||||
end
|
||||
|
||||
def delete(key, &block)
|
||||
@ordered_keys.delete(key)
|
||||
super
|
||||
end
|
||||
|
||||
def delete_if(&block)
|
||||
self.each { |k,v|
|
||||
if yield k, v
|
||||
delete(k)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def clear
|
||||
super
|
||||
@ordered_keys = []
|
||||
end
|
||||
|
||||
end # Ruby before 1.9
|
||||
|
||||
end
|
||||
|
|
|
@ -82,4 +82,21 @@ class OrderedHashTest < Test::Unit::TestCase
|
|||
assert_equal '{"c"=>1, "a"=>2, "z"=>3}', @oh.inspect
|
||||
end
|
||||
|
||||
def test_clear
|
||||
@oh.clear
|
||||
assert @oh.keys.empty?
|
||||
end
|
||||
|
||||
def test_delete
|
||||
assert @oh.keys.include?('z')
|
||||
@oh.delete('z')
|
||||
assert !@oh.keys.include?('z')
|
||||
end
|
||||
|
||||
def test_delete_if
|
||||
assert @oh.keys.include?('z')
|
||||
@oh.delete_if { |k,v| k == 'z' }
|
||||
assert !@oh.keys.include?('z')
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue