Project

General

Profile

Feature #15917

Pattern matching for Struct

Added by marcandre (Marc-Andre Lafortune) 5 months ago. Updated 2 days ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:93074]

Description

Structs respond to deconstruct, not to deconstruct_keys. Shouldn't we also implement it?

A = Struct.new(:foo, :bar)

case A.new(1, 2)
in foo: 1, **rest
  p "match"
else
  p "no match"
end
# => "no match", should be "match"

Associated revisions

Revision d4da74ea
Added by ktsj (Kazuki Tsujimoto) 5 days ago

Define Struct#deconstruct_keys

History

#1

Updated by jeremyevans0 (Jeremy Evans) 5 months ago

  • Backport deleted (2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN)
  • Tracker changed from Bug to Feature

Updated by ko1 (Koichi Sasada) 4 months ago

  • Assignee set to ktsj (Kazuki Tsujimoto)
#3

Updated by ktsj (Kazuki Tsujimoto) 2 days ago

  • Status changed from Open to Closed

Also available in: Atom PDF