Skip to content

Instantly share code, notes, and snippets.

@arches
Created October 4, 2013 15:08
Show Gist options
  • Select an option

  • Save arches/6827513 to your computer and use it in GitHub Desktop.

Select an option

Save arches/6827513 to your computer and use it in GitHub Desktop.
so SOMETIMES you can return from inside a block...?
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