Implement BSON::OrderedHash#dup
This commit is contained in:
parent
132c319ddd
commit
08daf9c5f9
|
@ -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(", ")
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue