Last active
April 27, 2017 05:49
-
-
Save Sihui/fb95997104ee0f1a704747afabb64b49 to your computer and use it in GitHub Desktop.
For [Code Block, Proc, Lambda, and Closure in Ruby]()
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
#Proc | |
#1. Proc.new followed by a code block | |
Proc.new { puts 'Hi' } | |
Proc.new do | |
puts 'Hi' | |
end | |
#2. proc followed by a code block | |
proc { puts 'Hi' } | |
proc do | |
puts 'Hi' | |
end | |
#arguments are | |
# wrapped between || | |
times_2 = proc { |num| num * 2 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment