Skip to content

Comment on ES6 in Depth: Destructuringparent

Comments

You're quite right, I meant to add `values_at` in the hash example! And the syntax is still not so nice:

  irb(main):005:0> a, b = {:a => 1, :b => 2}.values_at(:a, :b)
  => [1, 2]
Or:
  irb(main):006:0> a, b = (h = {:a => 1, :b => 2}).values_at(*h.keys)
  => [1, 2]
Edit: Ruby's hashes are ordered since 1.9, incidentally.

a, b = {a: 1, b: 2}.values

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.