Created
September 13, 2015 11:19
-
-
Save tsevdos/785589e80ca881c642d5 to your computer and use it in GitHub Desktop.
Ruby tips : block_given? on yields
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 yo | |
if block_given? | |
yield | |
else | |
puts "No block :-(" | |
end | |
end | |
yo # => No block :-( | |
yo { puts "Yo man" } # => Yo man |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment