Last active
August 29, 2015 13:58
-
-
Save bloudermilk/10324323 to your computer and use it in GitHub Desktop.
Example of yield in ruby
This file contains hidden or 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 my_fancy_method | |
# Call the block with 1 | |
yield 1 | |
# Call the block with "cat" | |
yield "cat" | |
# Call the block with nothing (i.e. nil) | |
yield | |
end | |
# Call my_fancy_method and print whatever is passed to the block | |
my_fancy_method do |lol| | |
puts lol | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment