Skip to content

Instantly share code, notes, and snippets.

@Sihui
Last active April 27, 2017 06:03
Show Gist options
  • Save Sihui/5e7c45cce55a73eabbd45fdf60147364 to your computer and use it in GitHub Desktop.
Save Sihui/5e7c45cce55a73eabbd45fdf60147364 to your computer and use it in GitHub Desktop.
For [Code Block, Proc, Lambda, and Closure in Ruby]()
# 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