Last active
April 27, 2017 06:03
-
-
Save Sihui/5e7c45cce55a73eabbd45fdf60147364 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
# Passing a proc into a method | |
def give_me_a_proc(pr) | |
puts 'Before call the proc' | |
pr.call | |
puts 'After calling the proc' | |
end | |
noisy_proc = proc { puts 'Noisy' } | |
give_me_a_proc(noisy_proc) | |
# The above code will print: | |
# Before call the proc | |
# Noisy | |
# After calling the proc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment