Created
August 21, 2014 11:19
-
-
Save p886/0dc3d4807c764f116775 to your computer and use it in GitHub Desktop.
Ruby to_proc Example
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
def say(a_proc_obj) | |
a_proc_obj.call | |
end | |
def tell | |
yield | |
end | |
a_lambda = -> { puts "there you go" } | |
# both will output "there you go" | |
say(a_lambda) | |
# ampersand implies Proc object. Ruby takes it from the parameter list and converts it into a block | |
tell(&a_lambda) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment