From 4a2b055cdd7b006e77f0d0cb82cb0e8c546027f9 Mon Sep 17 00:00:00 2001 From: Ichito Nagata Date: Fri, 1 Jun 2018 12:48:17 +0900 Subject: let Hash#merge keep ifnone value --- mrblib/hash.rb | 3 +-- 1 file changed, 1 insertion(+), 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] -- cgit v1.2.3