Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby hash equivalent of JavaScript's object initializer ES6 shorthand

In JavaScript ES6 we can create objects where variable names become keys like this:

> let a = 'aaa'
'aaa'

> let b = 'bbb'
'bbb'

> { a, b }
{ a:"aaa", b:"bbb" }

Does Ruby have something equivalent for hashes?

Clarification: Obviously this question regards the shorthand notation. I'm looking for {a,b} not {a:a,b:b}.

like image 221
Chris Avatar asked May 21 '16 16:05

Chris


1 Answers

Update: will be in 3.1 https://bugs.ruby-lang.org/issues/14579#note-14

No, there is no such shorthand notation.

Related proposals: #11105 #13137

Rejected. I saw JavaScript new syntax, but I had no sympathy. It doesn't make anything more understandable.

Matz.

like image 73
Pascal Avatar answered Oct 08 '22 16:10

Pascal