From: amirnaabuze@mail•ru
To: ruby-dev@ruby-lang.org
Subject: [ruby-dev:50332] [Ruby trunk Feature#14142] Add Method#===
Date: Wed, 29 Nov 2017 13:54:18 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-68052.20171129135416.9d88d350a5c3f37e@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-14142.20171129122601@ruby-lang.org
Issue #14142 has been updated by MusinAR (Amir Musin).
File Выделение_008.png added
![](Выделение_008.png)
----------------------------------------
Feature #14142: Add Method#===
https://bugs.ruby-lang.org/issues/14142#change-68052
* Author: osyo (manga osyo)
* Status: Open
* 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)
Выделение_008.png (21.5 KB)
--
https://bugs.ruby-lang.org/
next prev parent reply other threads:[~2017-11-29 13:54 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 ` amirnaabuze [this message]
2017-12-04 11:28 ` [ruby-dev:50336] " aycabta
2017-12-12 8:25 ` [ruby-dev:50344] " matz
2017-12-17 15:02 ` [ruby-dev:50355] " manga.osyo
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-68052.20171129135416.9d88d350a5c3f37e@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).