# Odd error

**URL:** <https://www.ruby-forum.com/t/odd-error/119753>\
**Category:** Ruby\
**Created:** [November 10, 2007, 12:13am UTC](https://www.ruby-forum.com/t/odd-error/119753 "2007-11-10T00:13:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [November 10, 2007, 12:13am UTC](https://www.ruby-forum.com/t/odd-error/119753/1 "2007-11-10T00:13:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [November 10, 2007, 12:20am UTC](https://www.ruby-forum.com/t/odd-error/119753/2 "2007-11-10T00:20:25Z")

</div>

On 9-Nov-07, at 6:13 PM, Roger P. wrote:

> 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

* * *

Bob H. – tumblelog at  
[http://www.recursive.ca/so/](http://www.recursive.ca/so/)  
Recursive Design Inc. – weblog at  
[http://www.recursive.ca/hutch](http://www.recursive.ca/hutch)  
[http://www.recursive.ca/](http://www.recursive.ca/) – works on  
[http://www.raconteur.info/cms-for-static-content/home/](http://www.raconteur.info/cms-for-static-content/home/)

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [November 10, 2007, 1:40am UTC](https://www.ruby-forum.com/t/odd-error/119753/3 "2007-11-10T01:40:28Z")

</div>

Hi,

On Sat, 2007-11-10 at 08:19 +0900, Bob H. wrote:

> 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.

Right. “=\>” is the tASSOC that ruby’s talking about. Since it thought  
you were having a block there, the only valid thing you could have  
after :a would be an end of block (i.e. :a is your return value).

> Cheers,  
> Bob

Arlen
