Created
August 6, 2015 15:58
-
-
Save ggarnier/1b9db2f739ed7b6e7e1e to your computer and use it in GitHub Desktop.
Ruby block has a different priority when using "do..end" or "{}"
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 test1(params) | |
p "test1 #{params}" | |
end | |
def test2(&block) | |
if block_given? | |
p "test2 with block" | |
yield | |
else | |
p "test2 without block" | |
end | |
"test2" | |
end | |
test1 data: test2 do | |
p "block with 'do..end'" | |
end | |
test1 data: test2 { | |
p "block with '{}'" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment