ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
From: manga.osyo@gmail•com
To: ruby-dev@ruby-lang.org
Subject: [ruby-dev:50355] [Ruby trunk Feature#14142] Add Method#===
Date: Sun, 17 Dec 2017 15:02:47 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-68468.20171217150245.708b683898d44353@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-14142.20171129122601@ruby-lang.org

Issue #14142 has been updated by osyo (manga osyo).


返信が遅れてしまいましたが、ありがとうございました。

----------------------------------------
Feature #14142: Add Method#===
https://bugs.ruby-lang.org/issues/14142#change-68468

* Author: osyo (manga osyo)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
## 概要

Ruby の `Method` クラスに対する提案になります。  
初めてこちらを利用するので内容や書き方などに対する問題があれば教えていただけると助かります。


## 提案

`Method#call` と同等の `Method#===` を定義する。


## 理由

`Proc` では `Proc#===` が `Proc#call` の同等のメソッドとして定義されています。
`Method` が `Proc` のように振る舞うことを期待するのであれば、`Proc#===` と同等の `Method#===` が定義されている方がよいのではないでしょうか。


## ユースケース

以下のようにして `Proc` と同様に `when` で使用する事が出来るようになります。

```ruby
# when で使用する
def check value
	case value
	when 0.method(:<)
		"plus"
	when 0.method(:>)
		"minus"
	when 0.method(:==)
		"zero"
	end
end

p check 3   # => "plus"
p check -6  # => "minus"
p check 0   # => "zero"
```


## 問題点

`Method#===` が `Object#===` を呼び出すことを期待しているようなコードであれば意図しない動作になる可能性があります。


---Files--------------------------------
add_method_eqq.patch (1.06 KB)


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

      parent reply	other threads:[~2017-12-17 15:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-14142.20171129122601@ruby-lang.org>
2017-11-29 12:26 ` [ruby-dev:50329] [Ruby trunk Feature#14142] Add Method#=== manga.osyo
2017-11-29 13:51 ` [ruby-dev:50330] " amirnaabuze
2017-11-29 13:52 ` [ruby-dev:50331] " amirnaabuze
2017-11-29 13:54 ` [ruby-dev:50332] " amirnaabuze
2017-12-04 11:28 ` [ruby-dev:50336] " aycabta
2017-12-12  8:25 ` [ruby-dev:50344] " matz
2017-12-17 15:02 ` manga.osyo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-68468.20171217150245.708b683898d44353@ruby-lang.org \
    --to=ruby-dev@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).