-
-
Save anonymous/043e3544b867482c9aae to your computer and use it in GitHub Desktop.
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 foo(option, &block) | |
if block_given? bar(option, &block) | |
else | |
bar(option) | |
end | |
end | |
def bar(option, &block) | |
p option | |
block.call if block_given? | |
end | |
> foo(3) | |
3 | |
# ArgumentError: wrong number of arguments(1 for 0) | |
#from (pry):25:in `block_given?' | |
> foo(3) { puts "tick" } | |
3 | |
tick | |
#ArgumentError: wrong number of arguments(1 for 0) | |
#from (pry):25:in `block_given?' | |
def taz(option, &block) | |
p option | |
block.call if block_given? | |
end | |
taz(3) { puts "FOO" } | |
3 | |
FOO | |
#=> nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment