OrderedHash#update should alias to merge bang
This commit is contained in:
parent
ba2b23476d
commit
41c680b491
|
@ -88,6 +88,8 @@ class OrderedHash < Hash
|
||||||
super(other)
|
super(other)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
alias :update :merge!
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
str = '{'
|
str = '{'
|
||||||
str << (@ordered_keys || []).collect { |k| "\"#{k}\"=>#{self.[](k).inspect}" }.join(", ")
|
str << (@ordered_keys || []).collect { |k| "\"#{k}\"=>#{self.[](k).inspect}" }.join(", ")
|
||||||
|
|
|
@ -130,6 +130,14 @@ class OrderedHashTest < Test::Unit::TestCase
|
||||||
assert_equal ['crab', 'apple', 3, 'foo'], @oh.values
|
assert_equal ['crab', 'apple', 3, 'foo'], @oh.values
|
||||||
end
|
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
|
def test_inspect_retains_order
|
||||||
assert_equal '{"c"=>1, "a"=>2, "z"=>3}', @oh.inspect
|
assert_equal '{"c"=>1, "a"=>2, "z"=>3}', @oh.inspect
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue