odd error

R

Roger Pack

irb(main):006:0> {}.merge {:a => 3}
SyntaxError: compile error
(irb):6: syntax error, unexpected tASSOC, expecting '}'
{}.merge {:a => 3}

???
{}.merge({:a => 3}) works, though. Is this a grammar problem?
 
B

Bob Hutchison

irb(main):006:0> {}.merge {:a => 3}
SyntaxError: compile error
(irb):6: syntax error, unexpected tASSOC, expecting '}'
{}.merge {:a => 3}

???
{}.merge({:a => 3}) works, though. Is this a grammar problem?


Ambiguity I guess.

It is taking the {:a => 3} as a block rather than as a hash argument
(merge is defined to allow that). The parenthesis resolves the
ambiguity.

Cheers,
Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top