Project

General

Profile

Feature #15881

Optimize deconstruct in pattern matching

Added by marcandre (Marc-Andre Lafortune) over 1 year ago. Updated 10 months ago.

Status:
Open
Priority:
Normal
Target version:
-
[ruby-core:92864]

Description

class A
  def deconstruct
    puts 'deconstruct called'
    [1]
  end
end

case A.new
in [2]
  2
in [1]
  1
else
end

Currently this outputs:

deconstruct called
deconstruct called
=> 1

Shouldn't deconstruct called print only once, whenever the first deconstruction needed occurs?


Related issues

Related to Ruby master - Feature #14912: Introduce pattern matching syntaxAssignedktsj (Kazuki Tsujimoto)Actions

Also available in: Atom PDF