Project

General

Profile

Actions

Feature #13137

closed

Hash Shorthand

Added by trevorlynnsmith (Trevor Smith) over 5 years ago. Updated about 5 years ago.

Status:
Rejected
Priority:
Normal
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

Also available in: Atom PDF