Created
March 4, 2014 23:21
-
-
Save chris-ramon/9357858 to your computer and use it in GitHub Desktop.
ruby procedures closures
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
# blocks | |
# most basic closure | |
# can not be saved | |
# wrong_proc = { puts 'hi' } | |
correct_proc = Proc.new { puts 'procedure' } | |
3.times { puts 'block' } # works | |
# 3.times proc # wont work | |
3.times(&correct_proc) | |
lambda_proc = lambda {|x| puts 'lambda' } | |
# dash rocket syntax | |
lambda_proc_2 = ->(x) { puts 'lambda v2' } | |
3.times(&lambda_proc) | |
3.times(&lambda_proc_2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment