Implement BSON::OrderedHash#dup
This commit is contained in:
parent
132c319ddd
commit
08daf9c5f9
|
@ -104,6 +104,15 @@ module BSON
|
||||||
|
|
||||||
alias :update :merge!
|
alias :update :merge!
|
||||||
|
|
||||||
|
def dup
|
||||||
|
result = OrderedHash.new
|
||||||
|
@ordered_keys ||= []
|
||||||
|
@ordered_keys.each do |key|
|
||||||
|
result[key] = self[key]
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
str = '{'
|
str = '{'
|
||||||
str << (@ordered_keys || []).collect { |k| "\"#{k}\"=>#{self.[](k).inspect}" }.join(", ")
|
str << (@ordered_keys || []).collect { |k| "\"#{k}\"=>#{self.[](k).inspect}" }.join(", ")
|
||||||
|
|
|
@ -194,4 +194,11 @@ class OrderedHashTest < Test::Unit::TestCase
|
||||||
copy[:foo] = 1
|
copy[:foo] = 1
|
||||||
assert copy.keys != @oh.keys
|
assert copy.keys != @oh.keys
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_dup
|
||||||
|
oh2 = @oh.dup
|
||||||
|
oh2['f'] = 9
|
||||||
|
assert_nil @oh['f']
|
||||||
|
assert_equal ['c', 'a', 'z'], @oh.keys
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue