Created
October 4, 2013 15:08
-
-
Save arches/6827513 to your computer and use it in GitHub Desktop.
so SOMETIMES you can return from inside a block...?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def foobar(&blk) | |
| yield "bar" if blk | |
| "foo" | |
| end | |
| > foobar | |
| => "foo" | |
| > foobar {|x| puts x} | |
| bar | |
| => "foo" | |
| > foobar { |x| return x } | |
| LocalJumpError: unexpected return | |
| from (irb):71:in `block in irb_binding' | |
| from (irb):66:in `foobar' | |
| from (irb):71 | |
| from /Users/chrisdoyle/.rbenv/versions/1.9.2-p320/bin/irb:12:in `<main>' | |
| > -> { foobar { |x| return x } }.call | |
| => "bar" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment