Added OrderedHash#inspect which preserves key order
This commit is contained in:
parent
5b83544b9c
commit
a9ba8c62fd
|
@ -51,4 +51,10 @@ class OrderedHash < Hash
|
||||||
super(other)
|
super(other)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def inspect
|
||||||
|
str = '{'
|
||||||
|
str << @ordered_keys.collect { |k| "\"#{k}\"=>#{self.[](k).inspect}" }.join(", ")
|
||||||
|
str << '}'
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -79,4 +79,8 @@ 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_inspect_retains_order
|
||||||
|
assert_equal '{"c"=>1, "a"=>2, "z"=>3}', @oh.inspect
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue