From 14e5c0c7b93cce8bd71c5bb9e1e7307ef39203eb Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 18 Jun 2022 08:10:25 +0900 Subject: [PATCH] hash.rb (merge): now takes multiple arguments. --- mrblib/hash.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/mrblib/hash.rb b/mrblib/hash.rb index ac70f4c70..826597b90 100644 --- a/mrblib/hash.rb +++ b/mrblib/hash.rb @@ -158,15 +158,20 @@ class Hash # will be the final value of this element. # # ISO 15.2.13.4.22 - def merge(other, &block) - raise TypeError, "Hash required (#{other.class} given)" unless Hash === other + def merge(*others, &block) + i=0; len=others.size h = self.dup - if block - other.each_key{|k| - h[k] = (self.has_key?(k))? block.call(k, self[k], other[k]): other[k] - } - else - other.each_key{|k| h[k] = other[k]} + while i