summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-hash-ext/mrblib/hash.rb
blob: 723a0b9070f6583ebb6e7658d3d497bb775dab95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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