OrderedHash#update should alias to merge bang

This commit is contained in:
Durran Jordan 2010-01-18 15:29:17 -05:00
parent ba2b23476d
commit 41c680b491
2 changed files with 10 additions and 0 deletions

View File

@ -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(", ")

View File

@ -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