From: "jeremyevans0 (Jeremy Evans)" Date: 2021-10-06T17:19:56+00:00 Subject: [ruby-core:105572] [Ruby master Feature#6414] Destructuring Assignment Issue #6414 has been updated by jeremyevans0 (Jeremy Evans). Status changed from Feedback to Closed This proposal has basically been implemented, with single-line pattern matching and valueless hash creation syntax: ```ruby john = {name: "John", last: "Smith"} john => {name:, last:} name # => "John" last # => "Smith" p({name:, last:}) ``` ---------------------------------------- Feature #6414: Destructuring Assignment https://bugs.ruby-lang.org/issues/6414#change-94029 * Author: edtsech (Edward Tsech) * Status: Closed * Priority: Normal ---------------------------------------- I mean: john = {name: "John", last: "Smith"} {name, last} = john # extract value by key from the hash and set to local variable with same name name # => "John" last # -> "Smith" Useful for ex. for "options" hashes: def select(options={}) {only, except} = options ... end As extra part of this feature can be hash constructing in this way: name = "John" last = "Smith" find({name, last}) # equals to => find({name: "John", last: "Smith"}) I think both really nice to have in Ruby. Thanks. ---Files-------------------------------- destructuring.pdf (128 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: