summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2018-06-01 20:29:45 +0900
committerGitHub <[email protected]>2018-06-01 20:29:45 +0900
commit7ed164ba896f5f3b0fca7c82e5b64230a432c842 (patch)
treec0cbbc862a4de4ecc8739125a3aec11f4cbddf52
parentb64ce17852b180dfeea81cf458660be41a78974d (diff)
parent4a2b055cdd7b006e77f0d0cb82cb0e8c546027f9 (diff)
downloadmruby-7ed164ba896f5f3b0fca7c82e5b64230a432c842.tar.gz
mruby-7ed164ba896f5f3b0fca7c82e5b64230a432c842.zip
Merge pull request #4031 from i110/i110/hash_default
let Hash#merge keep ifnone value
-rw-r--r--mrblib/hash.rb3
1 files changed, 1 insertions, 2 deletions
diff --git a/mrblib/hash.rb b/mrblib/hash.rb
index 6b4803ccb..7e1db905f 100644
--- a/mrblib/hash.rb
+++ b/mrblib/hash.rb
@@ -179,10 +179,9 @@ class Hash
#
# ISO 15.2.13.4.22
def merge(other, &block)
- h = {}
raise TypeError, "can't convert argument into Hash" unless other.respond_to?(:to_hash)
other = other.to_hash
- self.each_key{|k| h[k] = self[k]}
+ h = self.dup
if block
other.each_key{|k|
h[k] = (self.has_key?(k))? block.call(k, self[k], other[k]): other[k]