Skip to content

Commit

Permalink
Implement BSON::OrderedHash#dup
Browse files Browse the repository at this point in the history
  • Loading branch information
FooBarWidget authored and banker committed Mar 28, 2011
1 parent 132c319 commit 08daf9c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/bson/ordered_hash.rb
Expand Up @@ -103,6 +103,15 @@ def merge!(other)
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 = '{'
Expand Down
7 changes: 7 additions & 0 deletions test/bson/ordered_hash_test.rb
Expand Up @@ -194,4 +194,11 @@ def test_clone
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

0 comments on commit 08daf9c

Please sign in to comment.