mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user