mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
add Hash#to_h; ref #2348
This commit is contained in:
@@ -182,4 +182,15 @@ class Hash
|
||||
end
|
||||
nil
|
||||
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
|
||||
|
||||
@@ -115,3 +115,9 @@ assert("Hash#key") do
|
||||
assert_nil h.key('nil')
|
||||
assert_equal 'nil', h.key(nil)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user