Alexander Popov
Alexander Popov

Reputation: 25005

Hash is not recognized

The colon hash syntax works:

{ abc: 5 }
# => {:abc=>5}

However, puts {abc: 5} raises an error:

syntax error, unexpected ':', expecting '}'
puts {abc: 5}
         ^

I am using ruby 2.0.0. Why is that happening?

Upvotes: 1

Views: 91

Answers (1)

sawa
sawa

Reputation: 168269

The {} is recognized as a block. Put it in parentheses.

puts({abc: 5})

or

puts(abc: 5)

or

puts abc: 5

Upvotes: 4

Related Questions