diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2015-09-16 03:19:44 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2015-09-16 03:19:44 +0900 |
| commit | 08f9a3ed041c2461fb9264c7beb64ed16a8df4e9 (patch) | |
| tree | 87238bbad6dda8b0d5681c95307bd2ad245ce6ee | |
| parent | e91b7d640c8ac6af08f4571e71bb867b62fc4445 (diff) | |
| parent | b88ca625ab44a063c9b105f06789446f791c8b3e (diff) | |
| download | mruby-08f9a3ed041c2461fb9264c7beb64ed16a8df4e9.tar.gz mruby-08f9a3ed041c2461fb9264c7beb64ed16a8df4e9.zip | |
Merge pull request #2952 from takahashim/hash-fetch-block-key
fix block variable in Hash#fetch
| -rw-r--r-- | mrbgems/mruby-hash-ext/mrblib/hash.rb | 2 | ||||
| -rw-r--r-- | mrbgems/mruby-hash-ext/test/hash.rb | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/mrbgems/mruby-hash-ext/mrblib/hash.rb b/mrbgems/mruby-hash-ext/mrblib/hash.rb index c970b9d02..5056d0720 100644 --- a/mrbgems/mruby-hash-ext/mrblib/hash.rb +++ b/mrbgems/mruby-hash-ext/mrblib/hash.rb @@ -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 diff --git a/mrbgems/mruby-hash-ext/test/hash.rb b/mrbgems/mruby-hash-ext/test/hash.rb index e1afdaaa3..4950ef354 100644 --- a/mrbgems/mruby-hash-ext/test/hash.rb +++ b/mrbgems/mruby-hash-ext/test/hash.rb @@ -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 |
