summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-hash-ext/mrblib/hash.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2013-03-22 18:33:31 -0700
committerYukihiro "Matz" Matsumoto <[email protected]>2013-03-22 18:33:31 -0700
commit1ed2afeeca18c059a14ed4e97d747476eb625d53 (patch)
tree0477e2b7d2d4614e659776d1e9dd808b2c97d37c /mrbgems/mruby-hash-ext/mrblib/hash.rb
parentaf5f23d2cd2222256f3aab3af8c84d991fb38d8b (diff)
parentdfe2359b0c7d93864287d0566e49b118e16f288f (diff)
downloadmruby-1ed2afeeca18c059a14ed4e97d747476eb625d53.tar.gz
mruby-1ed2afeeca18c059a14ed4e97d747476eb625d53.zip
Merge pull request #1045 from kouki-o-iij/pr-hash-ext
add mruby-hash-ext mrbgem, and method: Hash#merge!
Diffstat (limited to 'mrbgems/mruby-hash-ext/mrblib/hash.rb')
-rw-r--r--mrbgems/mruby-hash-ext/mrblib/hash.rb12
1 files changed, 12 insertions, 0 deletions
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