Created
July 1, 2014 19:44
-
-
Save sstelfox/e739d6bdf1d1540c7943 to your computer and use it in GitHub Desktop.
Testing what happens when returning out of a block
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
| 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