From: mame@ruby-lang.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:89438] [Ruby trunk Feature#15231] Remove `Object#=~`
Date: Wed, 17 Oct 2018 08:46:52 +0000 (UTC) [thread overview]
Message-ID: <redmine.issue-15231.20181017084650.ca2d3b36146de1d8@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15231.20181017084650@ruby-lang.org
Issue #15231 has been reported by mame (Yusuke Endoh).
----------------------------------------
Feature #15231: Remove `Object#=~`
https://bugs.ruby-lang.org/issues/15231
* Author: mame (Yusuke Endoh)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
`Object#=~` receives (and just discards) an argument, and always returns nil. What purpose is this method for?
The following behavior that `Object#=~` caused was confusing to me.
```
["foo"] =~ /foo/ #=> nil
```
More precisely: the actual example that I encountered was to parse coverage data from output of coverage measurement tool by using `Open3.capture2`:
```
out = Open3.capture2("gcov", ...) # BUG: `out, =` was intended
if out ~= /lines\.*: *(\d+\.\d+)%/
...
end
```
Obviously, I forgot a comma to receive the return value of `Open3.capture2`. The method returns a two-element array, and `out ~=` calls `Object#=~`, which hided the bug. (Worse, I took several tens of minutes to debug it because I first thought that this is a bug of regexp, and spent tweaking the regexp.)
I guess `Object#=~` was intended for general pattern matching, but presently the role was taken over by `Object#===`.
So. How about removing `Object#=~`?
Concerns:
* @usa said `NilClass#=~` should be newly introduced because of: `if gets =~ /re/`
* `Object#!~` is difficult to remove: some classes define only `#=~`, and expect `Object#!~` to delegate to `#=~`.
--
https://bugs.ruby-lang.org/
next parent reply other threads:[~2018-10-17 8:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-15231.20181017084650@ruby-lang.org>
2018-10-17 8:46 ` mame [this message]
2018-10-17 8:51 ` [ruby-core:89440] [Ruby trunk Feature#15231] Remove `Object#=~` naruse
2018-10-18 6:12 ` [ruby-core:89455] " sawadatsuyoshi
2018-10-20 0:50 ` [ruby-core:89483] " zn
2018-11-22 22:29 ` [ruby-core:89986] " matz
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.issue-15231.20181017084650.ca2d3b36146de1d8@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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).