* [ruby-core:89438] [Ruby trunk Feature#15231] Remove `Object#=~`
[not found] <redmine.issue-15231.20181017084650@ruby-lang.org>
@ 2018-10-17 8:46 ` mame
2018-10-17 8:51 ` [ruby-core:89440] " naruse
` (3 subsequent siblings)
4 siblings, 0 replies; 5+ messages in thread
From: mame @ 2018-10-17 8:46 UTC (permalink / raw)
To: ruby-core
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/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:89440] [Ruby trunk Feature#15231] Remove `Object#=~`
[not found] <redmine.issue-15231.20181017084650@ruby-lang.org>
2018-10-17 8:46 ` [ruby-core:89438] [Ruby trunk Feature#15231] Remove `Object#=~` mame
@ 2018-10-17 8:51 ` naruse
2018-10-18 6:12 ` [ruby-core:89455] " sawadatsuyoshi
` (2 subsequent siblings)
4 siblings, 0 replies; 5+ messages in thread
From: naruse @ 2018-10-17 8:51 UTC (permalink / raw)
To: ruby-core
Issue #15231 has been updated by naruse (Yui NARUSE).
rubocop should alert `obj =~ re` to fix as `re =~ obj`.
----------------------------------------
Feature #15231: Remove `Object#=~`
https://bugs.ruby-lang.org/issues/15231#change-74478
* 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/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:89455] [Ruby trunk Feature#15231] Remove `Object#=~`
[not found] <redmine.issue-15231.20181017084650@ruby-lang.org>
2018-10-17 8:46 ` [ruby-core:89438] [Ruby trunk Feature#15231] Remove `Object#=~` mame
2018-10-17 8:51 ` [ruby-core:89440] " naruse
@ 2018-10-18 6:12 ` sawadatsuyoshi
2018-10-20 0:50 ` [ruby-core:89483] " zn
2018-11-22 22:29 ` [ruby-core:89986] " matz
4 siblings, 0 replies; 5+ messages in thread
From: sawadatsuyoshi @ 2018-10-18 6:12 UTC (permalink / raw)
To: ruby-core
Issue #15231 has been updated by sawa (Tsuyoshi Sawada).
I agree. At the same time, the `String=~` behaviour:
>str =~ obj → integer or nil click to toggle source
Match—If obj is a Regexp, use it as a pattern to match against str,and returns the position the match starts, or nil if there is no match. Otherwise, invokes obj.=~, passing str as an argument. The default =~ in Object returns nil.
(from https://ruby-doc.org/core-2.4.0/String.html#method-i-3D~)
should be changed to raise a `TypeError` when `obj` is not a `Regexp`, on a par with `Regexp#=~` given a non-`String` argument. Afterall, the following unnatural asymmetry in the current behaviour should be resolved:
```ruby
// =~ Object.new # >> TypeError: no implicit conversion of Object into String
"" =~ Object.new # => nil
```
----------------------------------------
Feature #15231: Remove `Object#=~`
https://bugs.ruby-lang.org/issues/15231#change-74495
* 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.
```RUBY
["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`:
```RUBY
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 hid 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/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:89483] [Ruby trunk Feature#15231] Remove `Object#=~`
[not found] <redmine.issue-15231.20181017084650@ruby-lang.org>
` (2 preceding siblings ...)
2018-10-18 6:12 ` [ruby-core:89455] " sawadatsuyoshi
@ 2018-10-20 0:50 ` zn
2018-11-22 22:29 ` [ruby-core:89986] " matz
4 siblings, 0 replies; 5+ messages in thread
From: zn @ 2018-10-20 0:50 UTC (permalink / raw)
To: ruby-core
Issue #15231 has been updated by znz (Kazuhiro NISHIYAMA).
```ruby
"" =~ "" #=> TypeError (type mismatch: String given)
```
----------------------------------------
Feature #15231: Remove `Object#=~`
https://bugs.ruby-lang.org/issues/15231#change-74524
* 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.
```RUBY
["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`:
```RUBY
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 hid 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/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [ruby-core:89986] [Ruby trunk Feature#15231] Remove `Object#=~`
[not found] <redmine.issue-15231.20181017084650@ruby-lang.org>
` (3 preceding siblings ...)
2018-10-20 0:50 ` [ruby-core:89483] " zn
@ 2018-11-22 22:29 ` matz
4 siblings, 0 replies; 5+ messages in thread
From: matz @ 2018-11-22 22:29 UTC (permalink / raw)
To: ruby-core
Issue #15231 has been updated by matz (Yukihiro Matsumoto).
I vote for the proposed change. Let's give deprecation warning first. I don't think we need to remove `!~` from `Kernel`.
Matz.
----------------------------------------
Feature #15231: Remove `Object#=~`
https://bugs.ruby-lang.org/issues/15231#change-75091
* 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.
```RUBY
["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`:
```RUBY
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 hid 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/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-11-22 22:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <redmine.issue-15231.20181017084650@ruby-lang.org>
2018-10-17 8:46 ` [ruby-core:89438] [Ruby trunk Feature#15231] Remove `Object#=~` mame
2018-10-17 8:51 ` [ruby-core:89440] " 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
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).