diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-04-04 10:50:42 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-04-04 10:50:42 +0900 |
| commit | 28ab1062925b99118c0aa307e2c7d2a23fc0fc29 (patch) | |
| tree | 00d0bf04603eee6ce1ac0c1ece375bde9f15ecbc /mrblib | |
| parent | 7a9630a5bb9534ab266aa225d728935ad648b861 (diff) | |
| download | mruby-28ab1062925b99118c0aa307e2c7d2a23fc0fc29.tar.gz mruby-28ab1062925b99118c0aa307e2c7d2a23fc0fc29.zip | |
Hash#replace to preserve order; close #2001
Diffstat (limited to 'mrblib')
| -rw-r--r-- | mrblib/hash.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/mrblib/hash.rb b/mrblib/hash.rb index 853f6ed97..1f2358a52 100644 --- a/mrblib/hash.rb +++ b/mrblib/hash.rb @@ -143,6 +143,20 @@ class Hash end ## + # Replaces the contents of <i>hsh</i> with the contents of other hash + # + # ISO 15.2.13.4.23 + def replace(hash) + self.clear + hash.each_key{|k| + self[k] = hash[k] + } + self + end + # ISO 15.2.13.4.17 + alias initialize_copy replace + + ## # Return a hash which contains the content of # +self+ and +other+. If a block is given # it will be called for each element with |
