Feature #13137
closed
Added by trevorlynnsmith (Trevor Smith) almost 8 years ago.
Updated over 7 years ago.
Description
The ES6 update to Javascript added object shorthand. I propose that a similar hash shorthand be added to Ruby.
Before¶
name = 'Matz'
country = 'Japan'
attributes = {
name: name,
country: country
}
After¶
name = 'Matz'
country = 'Japan'
attributes = {
name,
country
}
This would be very useful when building hashes from keyword arguments (especially with default values):
def build(name: 'John Doe', age: 100, country: 'Earth', )
attributes = {
name,
age,
country
}
end
While I understand the primary reasoning behind it - less to type - I do not like the syntax proposal.
To me it looks as if there is something missing in the build-up of the hash elements.
It appears to put load onto my brain and appears to be inconsistent with how I would normally populate a hash with key-value pairs.
Perhaps one day we could use some advanced hash that does all of these things including hash with indifferent syntax.
But I think it would be better for core hash to stay the way it is without any new implicit syntax.
To quote matz though, he wrote in the other thread that there may be a chance to revisit it in the future, e. g. when ES6 syntax may be more popular.
My apologies – I searched extensively and did not find the previous feature request. Thank you for the consideration.
- Status changed from Open to Rejected
Rejected. I saw JavaScript new syntax, but I had no sympathy. It doesn't make anything more understandable.
Matz.
Note: such culture seems to come from SGML.
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0