Skip to content

Instantly share code, notes, and snippets.

@pquimo
Last active December 14, 2015 19:09
Show Gist options
  • Save pquimo/5135035 to your computer and use it in GitHub Desktop.
Save pquimo/5135035 to your computer and use it in GitHub Desktop.
using RubyTapas episode 070 "break" as inspiration, try an on-the-fly version of the technique... which unfortunately doesn't work...
names = Proc.new do |&blk|
blk.call("Ylva")
blk.call("Brighid")
end
names.call do |name|
puts name
end
@pquimo
Copy link
Author

pquimo commented Mar 11, 2013

When I run this, here's the error:

"undefined method `names' for main:Object (NoMethodError)"

@avdi
Copy link

avdi commented Mar 11, 2013

since names is a Proc, not a method, you need to do names.call ...

@pquimo
Copy link
Author

pquimo commented Mar 11, 2013

Yeh I tried that also previously. Unfortunately, then the yield calls starting on line 2 result in this error:

"no block given (yield) (LocalJumpError)"

So I decided to search a bit, and found this:

http://stackoverflow.com/questions/4982630/trouble-yielding-inside-a-block-lambda

I have now updated the code to a version that works. Not sure if I'll use it, but glad to understand the different pieces involved better. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment