From: mame@... Date: 2018-10-17T08:46:52+00:00 Subject: [ruby-core:89438] [Ruby trunk Feature#15231] Remove `Object#=~` 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/ Unsubscribe: