How to force a LocalJumpError on return in Ruby? -
my function bar
gets block, , i'd run block without allowing return
. how do modifying bar
below, , keeping else, including foo
, intact?
def bar() yield end def foo() bar p "it" return # works. i'd localjumperror. end end foo
well, localjumperror
when try , pass block return
proc
(as opposed lambda
).
you can away not changing foo
except how it's called, if like
def bar() proc.new end def foo() bar p "it" return end end foo[]
that gives localjumperror
.
anyway, this article might help.
edit: return
in proc return outer method, not anonymous method in block. might able set flag can check in bar
see if returned prematurely:
bar_finished = false def bar(&block) proc = proc.new &block l.call bar_finished = true end
then, if return
in block passed bar
, bar_finished
still false. not sure if adding non-local variable option, if so, track returns block , throw whatever exception want if happens.
Comments
Post a Comment