B
B
Bogdan2017-05-12 19:54:33
Ruby on Rails
Bogdan, 2017-05-12 19:54:33

Destructuring assignment in Ruby?

Hello, is there a possibility in Ruby of destructive assignment, such as in JS
For example

({a, b} = {a:1, b:2, c:3, d:4});

console.log(a);
console.log(b);

or here one line will not work and you have to do it anyway? Is there a prettier solution?
obj =  {a:1, b:2, c:3, d:4} 
a = obj[:a]
b = obj[:b]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question