Project

General

Profile

Actions

Feature #20040

open

Make Hash respond do deconstruct to allow matchting key/value pairs

Added by Anonymous 12 months ago. Updated 12 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:115592]

Description

It would be nice to allow pattern matching to work on key/value pairs of a Hash to e.g. find the first entry, or entries where the key is not known.

Example:

class Hash; def deconstruct = to_a; end

{a: 1, b: 2} => [[k, v], *]
puts "k=#{k}" # :a
puts "v=#{v}" # 1

{a: 1, b: 2} => [*, [k, 2], *]
puts "k=#{k}" # :b
Actions

Also available in: Atom PDF

Like1
Like1