Commit c35a25c5 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #3091 from visualsayed/fix_hash_replace_method

protect NoMethodError from calling to_hash in replace
parents 2723b10a f5f48d94
......@@ -154,6 +154,7 @@ class Hash
#
# 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|
......
......@@ -239,6 +239,10 @@ assert('Hash#replace', '15.2.13.4.23') do
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment