Skip to content

Commit

Permalink
protect NoMethodError from calling to_hash in replace
Browse files Browse the repository at this point in the history
  • Loading branch information
visualsayed committed Jan 27, 2016
1 parent 2723b10 commit f5f48d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions mrblib/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def each_value(&block)
#
# ISO 15.2.13.4.23
def replace(hash)
raise TypeError, "can't convert argument into Hash" unless hash.respond_to?(:to_hash)
self.clear
hash = hash.to_hash
hash.each_key{|k|
Expand Down
4 changes: 4 additions & 0 deletions test/t/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@
a = Hash.new{|h,x| x}
b.replace(a)
assert_equal(127, b[127])

assert_raise(TypeError) do
{ 'abc_key' => 'abc_value' }.replace "a"
end
end

assert('Hash#shift', '15.2.13.4.24') do
Expand Down

0 comments on commit f5f48d9

Please sign in to comment.