Created
June 9, 2010 13:46
-
-
Save titanous/431490 to your computer and use it in GitHub Desktop.
Fun with blocks!
This file contains 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 FunWithBlocks | |
attr_accessor :block | |
def test_helper | |
puts 'I am a really useful helper' | |
end | |
def run_block | |
instance_exec('arg!', &@block) | |
end | |
end | |
def foo | |
puts 'Yay!!' | |
test_helper | |
end | |
fun_block = Proc.new do |arg| | |
puts arg | |
test_helper | |
foo | |
end | |
fun = FunWithBlocks.new | |
fun.block = fun_block | |
fun.run_block | |
# OUTPUT | |
# arg! | |
# I am a really useful helper | |
# Yay!! | |
# I am a really useful helper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment