Problem: Hash#fetch doesn't raise KeyError when a key cannot be found

Solution: change the Exception class raised to KeyError when a key
cannot be found.
This commit is contained in:
Asmod4n
2015-09-17 13:28:09 +02:00
parent e6d9b450ba
commit 4bd98671bc
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -130,7 +130,7 @@ class Hash
elsif none != NONE
none
else
raise RuntimeError, "Key not found: #{key}"
raise KeyError, "Key not found: #{key}"
end
else
self[key]
@@ -156,7 +156,7 @@ class Hash
self.each do |k, v|
self.delete(k) if block.call(k, v)
end
end
self
end
+1 -1
View File
@@ -79,7 +79,7 @@ assert('Hash#fetch') do
begin
h.fetch("gnu")
rescue => e
assert_kind_of(StandardError, e);
assert_kind_of(KeyError, e);
end
end