ruby - Can I evaluate a block inside a Proc? -
can yield block inside proc? consider example:
a = proc.new yield end a.call puts "x" end what i'm trying achieve print x, interpreting ruby 2.0 raises localjumperror: no block given (yield).
no can't, because proc you've created independent yield - is, it's yield has no block in context. although can call procs specified parameters , thereby pass parameters proc, yield doesn't work based on specified parameters; executes block found within proc's closure. , proc's closure predefined; not modified because call later block.
so it's equivalent of typing 'yield' straight irb (not within method definitions) returns localjumperror: no block given (yield) error.
Comments
Post a Comment