Commit 658a00ba authored by yui-knk's avatar yui-knk

Change to raise TypeError (Hash#merge, #merge!)

parent e07a3731
......@@ -22,7 +22,7 @@ class Hash
#
def merge!(other, &block)
raise "can't convert argument into Hash" unless other.respond_to?(:to_hash)
raise TypeError, "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]
......
......@@ -16,6 +16,10 @@ assert('Hash#merge!') do
'xyz_key' => 'xyz_value' }, result_1)
assert_equal({'abc_key' => 'abc_value', 'cba_key' => 'cba_value',
'xyz_key' => 'xyz_value' }, result_2)
assert_raise(TypeError) do
{ 'abc_key' => 'abc_value' }.merge! "a"
end
end
assert('Hash#values_at') do
......
......@@ -179,7 +179,7 @@ class Hash
# ISO 15.2.13.4.22
def merge(other, &block)
h = {}
raise "can't convert argument into Hash" unless other.respond_to?(:to_hash)
raise TypeError, "can't convert argument into Hash" unless other.respond_to?(:to_hash)
other = other.to_hash
self.each_key{|k| h[k] = self[k]}
if block
......
......@@ -223,6 +223,10 @@ assert('Hash#merge', '15.2.13.4.22') do
'xyz_key' => 'xyz_value' }, result_1)
assert_equal({'abc_key' => 'abc_value', 'cba_key' => 'cba_value',
'xyz_key' => 'xyz_value' }, result_2)
assert_raise(TypeError) do
{ 'abc_key' => 'abc_value' }.merge "a"
end
end
assert('Hash#replace', '15.2.13.4.23') 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