Project

General

Profile

Actions

Feature #15526

open

New way to destruct an object hash

Added by alissonbruno.sa (Alisson Santos) over 2 years ago. Updated over 2 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:91028]

Description

JavaScript has a nice a neat way to destruct objects.

const person = { name: "John Doe", age: 33 };
const { name, age } =  person;

Erlang has a similar way to destruct a tuple:

Person = {"John Doe", 33}
{Name, Age} = Person

I think it's very handy and would be nice if we have something similar in Ruby.

config = { host: 'localhost', port: 3000 } 
{ host, port } = config

I know Ruby has Hash#values_at, but I think this way it's more readable and understandable

What do you guys think?

Actions

Also available in: Atom PDF