Merge pull request #2952 from takahashim/hash-fetch-block-key

fix block variable in Hash#fetch
This commit is contained in:
Yukihiro "Matz" Matsumoto
2015-09-16 03:19:44 +09:00
2 changed files with 2 additions and 1 deletions
+1 -1
View File
@@ -126,7 +126,7 @@ class Hash
def fetch(key, none=NONE, &block)
unless self.key?(key)
if block
block.call
block.call(key)
elsif none != NONE
none
else
+1
View File
@@ -75,6 +75,7 @@ assert('Hash#fetch') do
assert_equal "feline", h.fetch("cat")
assert_equal "mickey", h.fetch("mouse", "mickey")
assert_equal "minny", h.fetch("mouse"){"minny"}
assert_equal "mouse", h.fetch("mouse"){|k| k}
begin
h.fetch("gnu")
rescue => e