Implement BSON::OrderedHash#dup
This commit is contained in:
parent
132c319ddd
commit
08daf9c5f9
@ -103,6 +103,15 @@ module BSON
|
||||
end
|
||||
|
||||
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 = '{'
|
||||
|
@ -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
Block a user