Skip to content

Instantly share code, notes, and snippets.

@bravoecho
Created July 29, 2013 12:33
Show Gist options
  • Save bravoecho/6103998 to your computer and use it in GitHub Desktop.
Save bravoecho/6103998 to your computer and use it in GitHub Desktop.
capture a yielded value
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