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}
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With