Last active
December 15, 2015 12:59
-
-
Save ilake/5264175 to your computer and use it in GitHub Desktop.
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
| # 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