SyntaxError on the beginning of the block
-
28-10-2019 - |
سؤال
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
المحلول
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
نصائح أخرى
object = Special::MyObject.new('string') { "a block" }
لا تنتمي إلى StackOverflow