Skip to content

Instantly share code, notes, and snippets.

@titanous
Created June 9, 2010 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save titanous/431490 to your computer and use it in GitHub Desktop.
Save titanous/431490 to your computer and use it in GitHub Desktop.
Fun with blocks!
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