Skip to content

Instantly share code, notes, and snippets.

@ilake
Last active December 15, 2015 12:59
Show Gist options
  • Select an option

  • Save ilake/5264175 to your computer and use it in GitHub Desktop.

Select an option

Save ilake/5264175 to your computer and use it in GitHub Desktop.
# Understanding Ruby Blocks, Procs and Lambdas
# http://stackoverflow.com/questions/6372596/ruby-block-procs-and-instance-eval
# http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/
# Metaprogramming Ruby: class_eval and instance_eval
# http://www.jimmycuadra.com/posts/metaprogramming-ruby-class-eval-and-instance-eval
my_proc = proc do
puts "yeaaaaah"
end
puts "will it run?"
my_proc.call
def hug(&block)
p block
print "{"
instance_eval(&block)
yield
block.call
print "}"
end
hug { print 'wtf' }
def callbacks(procs)
procs[:starting].call
puts "Still going"
procs[:finishing].call
end
callbacks(:starting => Proc.new { puts "Starting" },
:finishing => Proc.new { puts "Finish" })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment