From dfe2359b0c7d93864287d0566e49b118e16f288f Mon Sep 17 00:00:00 2001 From: Kouki Ooyatsu Date: Fri, 22 Mar 2013 17:04:38 +0900 Subject: add mruby-hash-ext mrbgem, and method: Hash#merge! --- mrbgems/mruby-hash-ext/mrblib/hash.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 mrbgems/mruby-hash-ext/mrblib/hash.rb (limited to 'mrbgems/mruby-hash-ext/mrblib') diff --git a/mrbgems/mruby-hash-ext/mrblib/hash.rb b/mrbgems/mruby-hash-ext/mrblib/hash.rb new file mode 100644 index 000000000..3e1bac0a2 --- /dev/null +++ b/mrbgems/mruby-hash-ext/mrblib/hash.rb @@ -0,0 +1,12 @@ +class Hash + def merge!(other, &block) + 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 +end -- cgit v1.2.3