Merge pull request #2226 from yui-knk/hash-merge-error

Change to raise TypeError (Hash#merge, #merge!)
This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-05-10 11:14:55 +09:00
4 changed files with 10 additions and 2 deletions
+1 -1
View File
@@ -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]
+4
View File
@@ -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
+1 -1
View File
@@ -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
+4
View File
@@ -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