Comma used to separate keys and values in hash literals until 1.9

I’m reading “Programming Ruby 1.9 & 2.0” and there is a footnote that states:

“As of Ruby 1.9, a comma may no longer be used to separate keys and values in hash literals. A comma still appears between each key/value pair”.

So: how was that before 1.9? How was a comma used before to separate keys and values in hash literals?

I am not sure, but looks like this was the syntax:

> Hash['a', 100, 100, 200, true, false, nil, 'something']
=> {"a"=>100, 100=>200, true=>false, nil=>"something"}

https://ruby-doc.org/core-1.8.6/Hash.html

But this syntax works till date…

1 Like

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs