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)
|
||||
end
|
||||
|
||||
def inspect
|
||||
str = '{'
|
||||
str << @ordered_keys.collect { |k| "\"#{k}\"=>#{self.[](k).inspect}" }.join(", ")
|
||||
str << '}'
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -79,4 +79,8 @@ class OrderedHashTest < Test::Unit::TestCase
|
||||
assert_equal ['crab', 'apple', 3, 'foo'], @oh.values
|
||||
end
|
||||
|
||||
def test_inspect_retains_order
|
||||
assert_equal '{"c"=>1, "a"=>2, "z"=>3}', @oh.inspect
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user