[ruby-core:92777] [Ruby trunk Feature#15824] respond_to pattern for pattern match

From: matz@...
Date: 2019-05-22 08:57:51 UTC
List: ruby-core #92777
Issue #15824 has been updated by matz (Yukihiro Matsumoto).


Interesting idea. We need to investigate the idea further.

Matz.


----------------------------------------
Feature #15824: respond_to pattern for pattern match
https://bugs.ruby-lang.org/issues/15824#change-78142

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

respond_to pattern

```ruby
class Runner
  def run
  end

  def stop
  end
end

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



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next