Issue #8953 has been updated by ko1 (Koichi Sasada).

Category set to core
Assignee changed from charliesome (Charlie Somerville) to matz (Yukihiro Matsumoto)
Target version set to current: 2.1.0

Could you check it?
----------------------------------------
Feature #8953: `str =~ /pattern/` does not call =~ method if (1) str is a String, (2) /pattern/ is a Regexp literal
https://bugs.ruby-lang.org/issues/8953#change-42154

Author: gfx (Goro Fuji)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


The expression `a =~ b` does not call the =~ method in some cases.
I think it is a bug that results from optimizations.

See the following code for details:

Code that does not work as expected (shows nothing):

$ ruby -e 's = "foo"; class << s; def =~ (rhs); raise "a"; end; end;  s =~ /foo/' # does nothing

Code that works as expected (raises errors):

$ ruby -e 's = "foo"; class << s; def =~ (rhs); raise "a"; end; end;  s.=~ /foo/' # call =~ as a method
$ ruby -e 's = "foo"; class << s; def =~ (rhs); raise "a"; end; end;  s =~ -> { /foo/ }.call' # RHS is not a Regexp literal but a Regexp object
$ ruby -e 's = Objec.new; class << s; def =~ (rhs); raise "a"; end; end;  s =~ /foo/' # LHS is not a String



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