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

Was it helpful?

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
scroll top