Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add type check in Hash#merge! #1234

Merged
merged 1 commit into from

2 participants

@gzohari

Hash.merge! doesn't nil check.

bin/mruby -e "{}.merge!(nil)"
trace:
    [0] -e:1
-e:1: undefined method 'each_key' for nil (NoMethodError)

After fix:

bin/mruby -e "{}.merge!(nil)"                               
trace:
    [0] -e:1
-e:1: can't convert argument into Hash (RuntimeError)
@matz matz merged commit 11e70f2 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 3, 2013
  1. @gzohari
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 0 deletions.
  1. +1 −0  mrbgems/mruby-hash-ext/mrblib/hash.rb
View
1  mrbgems/mruby-hash-ext/mrblib/hash.rb
@@ -1,5 +1,6 @@
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]
Something went wrong with that request. Please try again.