Project

General

Profile

Actions

Feature #13137

closed

Hash Shorthand

Added by trevorlynnsmith (Trevor Smith) almost 8 years ago. Updated over 7 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:79126]

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

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #11105: ES6-like hash literalsRejectedActions
Actions #1

Updated by znz (Kazuhiro NISHIYAMA) almost 8 years ago

Updated by shevegen (Robert A. Heiler) almost 8 years ago

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.

Updated by trevorlynnsmith (Trevor Smith) almost 8 years ago

My apologies – I searched extensively and did not find the previous feature request. Thank you for the consideration.

Updated by matz (Yukihiro Matsumoto) almost 8 years ago

  • 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.

Updated by naruse (Yui NARUSE) over 7 years ago

Note: such culture seems to come from SGML.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0