Unverified Commit 7ed164ba authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #4031 from i110/i110/hash_default

let Hash#merge keep ifnone value
parents b64ce178 4a2b055c
...@@ -179,10 +179,9 @@ class Hash ...@@ -179,10 +179,9 @@ class Hash
# #
# ISO 15.2.13.4.22 # ISO 15.2.13.4.22
def merge(other, &block) def merge(other, &block)
h = {}
raise TypeError, "can't convert argument into Hash" unless other.respond_to?(:to_hash) raise TypeError, "can't convert argument into Hash" unless other.respond_to?(:to_hash)
other = other.to_hash other = other.to_hash
self.each_key{|k| h[k] = self[k]} h = self.dup
if block if block
other.each_key{|k| other.each_key{|k|
h[k] = (self.has_key?(k))? block.call(k, self[k], other[k]): other[k] h[k] = (self.has_key?(k))? block.call(k, self[k], other[k]): other[k]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment