SyntaxError on the beginning of the block
-
28-10-2019 - |
Question
Can someone explain why this is wrong?
object = Special::MyObject.new 'string' { "a block" }
I get a SyntaxError
on
.. { "a ...
^
It expects a keyword_end
If I remove the block everything works fine
Solution
You can't use brace block ({ ... }
) with methods with no parentheses. You can use do ... end
or add (
... )
.
object = Special::MyObject.new('string') { "a block" }
object = Special::MyObject.new 'string' do
"a block"
end
OTHER TIPS
object = Special::MyObject.new('string') { "a block" }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow