diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-06-04 18:57:31 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-06-04 18:57:31 +0900 |
| commit | 172060877a80d5f1c5bd725dafd041c7180e9a28 (patch) | |
| tree | 510311b176210a88a1ab7dc7a59b785e556af38a | |
| parent | 8a9e2066c3124f6bcd65d724bd519265a7d6ebe9 (diff) | |
| download | mruby-172060877a80d5f1c5bd725dafd041c7180e9a28.tar.gz mruby-172060877a80d5f1c5bd725dafd041c7180e9a28.zip | |
add Hash#to_h; ref #2348
| -rw-r--r-- | mrbgems/mruby-hash-ext/mrblib/hash.rb | 11 | ||||
| -rw-r--r-- | mrbgems/mruby-hash-ext/test/hash.rb | 6 |
2 files changed, 17 insertions, 0 deletions
diff --git a/mrbgems/mruby-hash-ext/mrblib/hash.rb b/mrbgems/mruby-hash-ext/mrblib/hash.rb index 504848a74..9da08dc3a 100644 --- a/mrbgems/mruby-hash-ext/mrblib/hash.rb +++ b/mrbgems/mruby-hash-ext/mrblib/hash.rb @@ -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 diff --git a/mrbgems/mruby-hash-ext/test/hash.rb b/mrbgems/mruby-hash-ext/test/hash.rb index 62cfc8856..2bc5b911a 100644 --- a/mrbgems/mruby-hash-ext/test/hash.rb +++ b/mrbgems/mruby-hash-ext/test/hash.rb @@ -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 |
