Created
February 7, 2013 10:34
-
-
Save twoism-dev/4730151 to your computer and use it in GitHub Desktop.
A demo of how block returns.
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 Tester | |
@@blocks = [] | |
def self.add(&block) | |
@@blocks << block | |
end | |
def self.run | |
@@blocks.each_with_index do |block, n| | |
exec(n) | |
end | |
end | |
def self.exec(n) | |
@@blocks[n].call | |
end | |
end | |
def test | |
Tester.add do | |
puts 'block 1' | |
return 1 | |
end | |
Tester.add do | |
puts 'block 2' | |
end | |
Tester.run | |
end | |
test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tesr