Skip to content

Instantly share code, notes, and snippets.

@sstelfox
Created July 1, 2014 19:44
Show Gist options
  • Save sstelfox/e739d6bdf1d1540c7943 to your computer and use it in GitHub Desktop.
Save sstelfox/e739d6bdf1d1540c7943 to your computer and use it in GitHub Desktop.
Testing what happens when returning out of a block
module Klass
def self.counter
Thread.current[:counter] ||= 0
end
def self.counter=(value)
Thread.current[:counter] = value
end
def self.yield_with_counter
self.counter += 1
yield
ensure
self.counter -= 1
end
def self.measure
ret = nil
puts self.counter
yield_with_counter do
ret = yield
end
puts self.counter
ret
end
end
def testing
puts 'out'
Klass.measure do
puts 'in'
return 3
puts 'post'
end
puts 'double-post'
end
puts testing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment