Created
July 29, 2013 12:33
-
-
Save bravoecho/6103998 to your computer and use it in GitHub Desktop.
capture a yielded value
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
class MyClass | |
def initialize | |
@thevalue = 42 | |
end | |
def omg | |
yield @thevalue | |
end | |
end | |
myobj = MyClass.new | |
thevalue = catch(:thevalue) do | |
myobj.omg { |thevalue| | |
throw :thevalue, thevalue | |
thevalue * 2 | |
} | |
end | |
p thevalue # => 42 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment