diff --git a/lib/bson/ordered_hash.rb b/lib/bson/ordered_hash.rb index ed22e65..2bce466 100644 --- a/lib/bson/ordered_hash.rb +++ b/lib/bson/ordered_hash.rb @@ -88,7 +88,7 @@ module BSON @ordered_keys ||= [] @ordered_keys.map { |k| [k, self[k]] } end - + def values collect { |k, v| v } end @@ -158,6 +158,9 @@ module BSON end end + def clone + Marshal::load(Marshal.dump(self)) + end end end end diff --git a/test/mongo_bson/ordered_hash_test.rb b/test/mongo_bson/ordered_hash_test.rb index e059b35..0171c3d 100644 --- a/test/mongo_bson/ordered_hash_test.rb +++ b/test/mongo_bson/ordered_hash_test.rb @@ -187,4 +187,11 @@ class OrderedHashTest < Test::Unit::TestCase assert !new.keys.include?('z') end + def test_clone + copy = @oh.clone + assert copy.keys == @oh.keys + + copy[:foo] = 1 + assert copy.keys != @oh.keys + end end