From 41c680b491590b297c5191bc97ebc74d4fe14add Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Mon, 18 Jan 2010 15:29:17 -0500 Subject: [PATCH] OrderedHash#update should alias to merge bang --- lib/mongo/util/ordered_hash.rb | 2 ++ test/test_ordered_hash.rb | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/mongo/util/ordered_hash.rb b/lib/mongo/util/ordered_hash.rb index b8910a4..3e40091 100644 --- a/lib/mongo/util/ordered_hash.rb +++ b/lib/mongo/util/ordered_hash.rb @@ -88,6 +88,8 @@ class OrderedHash < Hash super(other) end + alias :update :merge! + def inspect str = '{' str << (@ordered_keys || []).collect { |k| "\"#{k}\"=>#{self.[](k).inspect}" }.join(", ") diff --git a/test/test_ordered_hash.rb b/test/test_ordered_hash.rb index 043e6dd..276cabb 100644 --- a/test/test_ordered_hash.rb +++ b/test/test_ordered_hash.rb @@ -130,6 +130,14 @@ class OrderedHashTest < Test::Unit::TestCase assert_equal ['crab', 'apple', 3, 'foo'], @oh.values end + def test_update + other = OrderedHash.new + other['f'] = 'foo' + noob = @oh.update(other) + assert_equal @ordered_keys + ['f'], noob.keys + assert_equal [1, 2, 3, 'foo'], noob.values + end + def test_inspect_retains_order assert_equal '{"c"=>1, "a"=>2, "z"=>3}', @oh.inspect end