diff options
| author | Asmod4n <[email protected]> | 2015-09-17 13:28:09 +0200 |
|---|---|---|
| committer | Asmod4n <[email protected]> | 2015-09-17 13:28:09 +0200 |
| commit | 4bd98671bc183ffa97ef5ee5766fc52466399b2b (patch) | |
| tree | d76ddf7ba72fa71721fcd6b35cbff6bb54398aa8 | |
| parent | e6d9b450bab46f218e6bee2c95114b733660951a (diff) | |
| download | mruby-4bd98671bc183ffa97ef5ee5766fc52466399b2b.tar.gz mruby-4bd98671bc183ffa97ef5ee5766fc52466399b2b.zip | |
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.
| -rw-r--r-- | mrbgems/mruby-hash-ext/mrblib/hash.rb | 4 | ||||
| -rw-r--r-- | mrbgems/mruby-hash-ext/test/hash.rb | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/mrbgems/mruby-hash-ext/mrblib/hash.rb b/mrbgems/mruby-hash-ext/mrblib/hash.rb index 5056d0720..ec8bd05fb 100644 --- a/mrbgems/mruby-hash-ext/mrblib/hash.rb +++ b/mrbgems/mruby-hash-ext/mrblib/hash.rb @@ -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 diff --git a/mrbgems/mruby-hash-ext/test/hash.rb b/mrbgems/mruby-hash-ext/test/hash.rb index 4950ef354..ef25acbe7 100644 --- a/mrbgems/mruby-hash-ext/test/hash.rb +++ b/mrbgems/mruby-hash-ext/test/hash.rb @@ -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 |
