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

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -