3 ms·
It's becoming quite common in JavaScript, but usually with a const/let keyword in front so it's easier for the brain to understand that you are reading a destru
by speedgoose 6y ago
It's becoming quite common in JavaScript, but usually with a const/let keyword in front so it's easier for the brain to understand that you are reading a destructuring assignment.
- izietto 6y agoExactly that, I use it all the time in JS. I can't see why Ruby can't adopt something like: params = { a: 1, b: 2 } { a: a } = params p a #=> 1
- latortuga 6y agoI believe you are misunderstanding how this new feature works in Ruby. You've brought up destructuring assignment in javascript which flows right-side values by key to left-side variables. In Ruby, this new syntax is "rightward" assignment, values flowing from left to right: 3 => x # assigns 3 to x [4, 5] => [x, y] # assigns 4 to x, 5 to y
- speedgoose 6y agoIndeed. It's very different. Thanks for the clarification.