Files
mruby-mruby/mrbgems/mruby-hash-ext/mrblib/hash.rb
T
2014-03-21 09:31:44 +09:00

17 lines
373 B
Ruby

class Hash
def merge!(other, &block)
raise "can't convert argument into Hash" unless other.respond_to?(:to_hash)
if block
other.each_key{|k|
self[k] = (self.has_key?(k))? block.call(k, self[k], other[k]): other[k]
}
else
other.each_key{|k| self[k] = other[k]}
end
self
end
alias each_pair each
alias update merge!
end