add Hash#to_h; ref #2348

parent 8a9e2066
...@@ -182,4 +182,15 @@ class Hash ...@@ -182,4 +182,15 @@ class Hash
end end
nil nil
end end
##
# call-seq:
# hsh.to_h -> hsh or new_hash
#
# Returns +self+. If called on a subclass of Hash, converts
# the receiver to a Hash object.
#
def to_h
self
end
end end
...@@ -115,3 +115,9 @@ assert("Hash#key") do ...@@ -115,3 +115,9 @@ assert("Hash#key") do
assert_nil h.key('nil') assert_nil h.key('nil')
assert_equal 'nil', h.key(nil) assert_equal 'nil', h.key(nil)
end end
assert("Hash#to_h") do
h = { "a" => 100, "b" => 200 }
assert_equal Hash, h.to_h.class
assert_equal h, h.to_h
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment