summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-hash-ext/mrblib/hash.rb
diff options
context:
space:
mode:
authorKouki Ooyatsu <[email protected]>2013-03-22 17:04:38 +0900
committerKouki Ooyatsu <[email protected]>2013-03-22 17:10:42 +0900
commitdfe2359b0c7d93864287d0566e49b118e16f288f (patch)
tree57b0b424511abdef30d28bf95bdb4421fbba273f /mrbgems/mruby-hash-ext/mrblib/hash.rb
parentb547a7ed2cc781500a572b3a24fdfba7aed85e40 (diff)
downloadmruby-dfe2359b0c7d93864287d0566e49b118e16f288f.tar.gz
mruby-dfe2359b0c7d93864287d0566e49b118e16f288f.zip
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