Implement BSON::OrderedHash#dup

This commit is contained in:
Hongli Lai (Phusion) 2011-03-24 00:49:33 +01:00 committed by Kyle Banker
parent 132c319ddd
commit 08daf9c5f9
2 changed files with 16 additions and 0 deletions

View File

@ -104,6 +104,15 @@ module BSON
alias :update :merge!
def dup
result = OrderedHash.new
@ordered_keys ||= []
@ordered_keys.each do |key|
result[key] = self[key]
end
result
end
def inspect
str = '{'
str << (@ordered_keys || []).collect { |k| "\"#{k}\"=>#{self.[](k).inspect}" }.join(", ")

View File

@ -194,4 +194,11 @@ class OrderedHashTest < Test::Unit::TestCase
copy[:foo] = 1
assert copy.keys != @oh.keys
end
def test_dup
oh2 = @oh.dup
oh2['f'] = 9
assert_nil @oh['f']
assert_equal ['c', 'a', 'z'], @oh.keys
end
end