diff options
| author | INOUE Yasuyuki <[email protected]> | 2014-09-18 17:43:38 +0900 |
|---|---|---|
| committer | INOUE Yasuyuki <[email protected]> | 2014-09-18 17:43:38 +0900 |
| commit | 5f16c41753f7789065f2c2bfe84395cad8cadcaa (patch) | |
| tree | fdbbee8ffbf6601e8965aeaae3a20b0dd5bf73f2 | |
| parent | d30aadf30626a16f8c83359fbb2205ee1e5fd464 (diff) | |
| download | mruby-5f16c41753f7789065f2c2bfe84395cad8cadcaa.tar.gz mruby-5f16c41753f7789065f2c2bfe84395cad8cadcaa.zip | |
copy documentation comment from CRuby
| -rw-r--r-- | mrbgems/mruby-hash-ext/mrblib/hash.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/mrbgems/mruby-hash-ext/mrblib/hash.rb b/mrbgems/mruby-hash-ext/mrblib/hash.rb index 82847c39b..f214cb1d5 100644 --- a/mrbgems/mruby-hash-ext/mrblib/hash.rb +++ b/mrbgems/mruby-hash-ext/mrblib/hash.rb @@ -3,6 +3,26 @@ class Hash # ISO does not define Hash#each_pair, so each_pair is defined in gem. alias each_pair each + ## + # call-seq: + # Hash[ key, value, ... ] -> new_hash + # Hash[ [ [key, value], ... ] ] -> new_hash + # Hash[ object ] -> new_hash + # + # Creates a new hash populated with the given objects. + # + # Similar to the literal <code>{ _key_ => _value_, ... }</code>. In the first + # form, keys and values occur in pairs, so there must be an even number of + # arguments. + # + # The second and third form take a single argument which is either an array + # of key-value pairs or an object convertible to a hash. + # + # Hash["a", 100, "b", 200] #=> {"a"=>100, "b"=>200} + # Hash[ [ ["a", 100], ["b", 200] ] ] #=> {"a"=>100, "b"=>200} + # Hash["a" => 100, "b" => 200] #=> {"a"=>100, "b"=>200} + # + def self.[](*object) o = object[0] if o.respond_to?(:to_hash) |
