Commit b88ca625 authored by takahashim's avatar takahashim

fix block variable in Hash#fetch

parent e91b7d64
...@@ -126,7 +126,7 @@ class Hash ...@@ -126,7 +126,7 @@ class Hash
def fetch(key, none=NONE, &block) def fetch(key, none=NONE, &block)
unless self.key?(key) unless self.key?(key)
if block if block
block.call block.call(key)
elsif none != NONE elsif none != NONE
none none
else else
......
...@@ -75,6 +75,7 @@ assert('Hash#fetch') do ...@@ -75,6 +75,7 @@ assert('Hash#fetch') do
assert_equal "feline", h.fetch("cat") assert_equal "feline", h.fetch("cat")
assert_equal "mickey", h.fetch("mouse", "mickey") assert_equal "mickey", h.fetch("mouse", "mickey")
assert_equal "minny", h.fetch("mouse"){"minny"} assert_equal "minny", h.fetch("mouse"){"minny"}
assert_equal "mouse", h.fetch("mouse"){|k| k}
begin begin
h.fetch("gnu") h.fetch("gnu")
rescue => e rescue => e
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment