Created
November 20, 2012 10:27
-
-
Save rauchy/4117153 to your computer and use it in GitHub Desktop.
Blocks In-depth: Calling Blocks
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 log | |
if block_given? | |
puts "before block" | |
yield | |
puts "after block" | |
end | |
end | |
log # nothing will be displayed! |
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 log | |
puts "before block" | |
yield | |
puts "after block" | |
end | |
log do | |
puts "o hai" | |
end |
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
some_method(some_argument) do | |
# block content goes here | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment