Last active
December 14, 2015 19:09
-
-
Save makanimason/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...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
names = Proc.new do |&blk| | |
blk.call("Ylva") | |
blk.call("Brighid") | |
end | |
names.call do |name| | |
puts name | |
end |
since names
is a Proc, not a method, you need to do names.call ...
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
When I run this, here's the error:
"undefined method `names' for main:Object (NoMethodError)"