Project

General

Profile

Feature #15824

respond_to pattern for pattern match

Added by fukajun (Jun Fukaya) 2 months ago. Updated about 2 months ago.

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

Description

rubyに追加されそうなパターンマッチの機能について...
Interger, Array など constantを書くことで、オブジェクトのクラスにマッチングさせる機能があるのを拝見しました。
duck typingを確認するようなパターンマッチがかけるとrubyらしいのではないかと思ってこちらに書いてみることにしました。

respond_to pattern

class Runner
  def run
  end

  def stop
  end
end

runner = Runner.new
case runner
in .run & .stop
  :reachable
in .start & .stop
  :unreachable
end 

Related issues

Related to Ruby master - Feature #14912: Introduce pattern matching syntaxAssignedActions

History

Updated by shevegen (Robert A. Heiler) 2 months ago

I don't want to comment so much on the issue as such, but I would like to point
out that it may be a better idea to start with a new idea not on highest
complexity. I am not sure if everyone fully understood pattern matching yet so
in my personal opinion it may be better to see how pattern matching is used
before making it more complex (including syntactic changes). But that's just
my opinion, anyway; some of the syntax appears to become no longer recognizable
ruby (to me).

Updated by matz (Yukihiro Matsumoto) about 2 months ago

Interesting idea. We need to investigate the idea further.

Matz.

#3

Updated by ktsj (Kazuki Tsujimoto) about 1 month ago

Also available in: Atom PDF