RUBY-287 OrderedHash#replace

This commit is contained in:
Kyle Banker 2011-06-15 16:25:20 -04:00
parent 3a602e1227
commit fbf7b754ac
2 changed files with 19 additions and 0 deletions

View File

@ -94,6 +94,11 @@ module BSON
collect { |k, v| v }
end
def replace(other)
@ordered_keys = other.keys
super
end
def merge(other)
oh = self.dup
oh.merge!(other)

View File

@ -76,6 +76,20 @@ class OrderedHashTest < Test::Unit::TestCase
assert_equal @ordered_keys, @oh.keys
end
def test_replace
h1 = BSON::OrderedHash.new
h1[:a] = 1
h1[:b] = 2
h2 = BSON::OrderedHash.new
h2[:c] = 3
h2[:d] = 4
h1.replace(h2)
assert_equal [:c, :d], h1.keys
assert_equal [3, 4], h1.values
end
def test_to_a_order_preserved
assert_equal @ordered_keys, @oh.to_a.map {|m| m.first}
end