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


I checked previous behavior.

versions/install-tags_v1_6_5_/bin/ruby
versions/install-tags_v1_6_6_/bin/ruby
versions/install-tags_v1_6_7_/bin/ruby
versions/install-tags_v1_6_8_/bin/ruby
versions/install-tags_v1_8_5_/bin/ruby
versions/install-tags_v1_8_5_113_/bin/ruby
versions/install-tags_v1_8_5_114_/bin/ruby
versions/install-tags_v1_8_5_115_/bin/ruby
versions/install-tags_v1_8_5_11_/bin/ruby
versions/install-tags_v1_8_5_12_/bin/ruby
versions/install-tags_v1_8_5_231_/bin/ruby
versions/install-tags_v1_8_5_2_/bin/ruby
versions/install-tags_v1_8_5_35_/bin/ruby
versions/install-tags_v1_8_5_52_/bin/ruby
versions/install-tags_v1_8_5_preview1_/bin/ruby
versions/install-tags_v1_8_5_preview2_/bin/ruby
versions/install-tags_v1_8_5_preview3_/bin/ruby
versions/install-tags_v1_8_5_preview4_/bin/ruby
versions/install-tags_v1_8_5_preview5_/bin/ruby
versions/install-tags_v1_8_6_/bin/ruby
versions/install-tags_v1_8_6_110_/bin/ruby
versions/install-tags_v1_8_6_111_/bin/ruby
versions/install-tags_v1_8_6_114_/bin/ruby
versions/install-tags_v1_8_6_230_/bin/ruby
versions/install-tags_v1_8_6_286_/bin/ruby
versions/install-tags_v1_8_6_287_/bin/ruby
versions/install-tags_v1_8_6_368_/bin/ruby
versions/install-tags_v1_8_6_369_/bin/ruby
versions/install-tags_v1_8_6_36_/bin/ruby
versions/install-tags_v1_8_6_383_/bin/ruby
versions/install-tags_v1_8_6_388_/bin/ruby
versions/install-tags_v1_8_6_398_/bin/ruby
versions/install-tags_v1_8_6_399_/bin/ruby
versions/install-tags_v1_8_6_420_/bin/ruby
versions/install-tags_v1_8_6_preview1_/bin/ruby
versions/install-tags_v1_8_6_preview2_/bin/ruby
versions/install-tags_v1_8_6_preview3_/bin/ruby
versions/install-tags_v1_8_7_/bin/ruby
versions/install-tags_v1_8_7_160_/bin/ruby
versions/install-tags_v1_8_7_173_/bin/ruby
versions/install-tags_v1_8_7_174_/bin/ruby
versions/install-tags_v1_8_7_17_/bin/ruby
versions/install-tags_v1_8_7_22_/bin/ruby
versions/install-tags_v1_8_7_248_/bin/ruby
versions/install-tags_v1_8_7_249_/bin/ruby
versions/install-tags_v1_8_7_299_/bin/ruby
versions/install-tags_v1_8_7_301_/bin/ruby
versions/install-tags_v1_8_7_302_/bin/ruby
versions/install-tags_v1_8_7_330_/bin/ruby
versions/install-tags_v1_8_7_334_/bin/ruby
versions/install-tags_v1_8_7_352_/bin/ruby
versions/install-tags_v1_8_7_357_/bin/ruby
versions/install-tags_v1_8_7_358_/bin/ruby
versions/install-tags_v1_8_7_369_/bin/ruby
versions/install-tags_v1_8_7_370_/bin/ruby
versions/install-tags_v1_8_7_371_/bin/ruby
versions/install-tags_v1_8_7_373_/bin/ruby
versions/install-tags_v1_8_7_374_/bin/ruby
versions/install-tags_v1_8_7_71_/bin/ruby
versions/install-tags_v1_8_7_72_/bin/ruby
versions/install-tags_v1_8_7_preview1_/bin/ruby
versions/install-tags_v1_8_7_preview2_/bin/ruby
versions/install-tags_v1_8_7_preview3_/bin/ruby
versions/install-tags_v1_8_7_preview4_/bin/ruby
versions/install-tags_v1_9_0_0_/bin/ruby
versions/install-tags_v1_9_0_1_/bin/ruby
versions/install-tags_v1_9_0_2_/bin/ruby
versions/install-tags_v1_9_0_3_/bin/ruby
versions/install-tags_v1_9_0_4_/bin/ruby
versions/install-tags_v1_9_0_5_/bin/ruby
versions/install-tags_v1_9_1_0_/bin/ruby
versions/install-tags_v1_9_1_126_/bin/ruby
versions/install-tags_v1_9_1_127_/bin/ruby
versions/install-tags_v1_9_1_128_/bin/ruby
versions/install-tags_v1_9_1_129_/bin/ruby
versions/install-tags_v1_9_1_243_/bin/ruby
versions/install-tags_v1_9_1_376_/bin/ruby
versions/install-tags_v1_9_1_378_/bin/ruby
versions/install-tags_v1_9_1_429_/bin/ruby
versions/install-tags_v1_9_1_430_/bin/ruby
versions/install-tags_v1_9_1_431_/bin/ruby
versions/install-tags_v1_9_1_preview1_/bin/ruby
versions/install-tags_v1_9_1_preview2_/bin/ruby
versions/install-tags_v1_9_1_rc1_/bin/ruby
versions/install-tags_v1_9_1_rc2_/bin/ruby
versions/install-tags_v1_9_2_0_/bin/ruby
versions/install-tags_v1_9_2_136_/bin/ruby
versions/install-tags_v1_9_2_180_/bin/ruby
versions/install-tags_v1_9_2_290_/bin/ruby
versions/install-tags_v1_9_2_318_/bin/ruby
versions/install-tags_v1_9_2_320_/bin/ruby
versions/install-tags_v1_9_2_preview1_/bin/ruby
versions/install-tags_v1_9_2_preview2_/bin/ruby
versions/install-tags_v1_9_2_preview3_/bin/ruby
versions/install-tags_v1_9_2_rc1_/bin/ruby
versions/install-tags_v1_9_2_rc2_/bin/ruby
versions/install-tags_v1_9_3_0_/bin/ruby
versions/install-tags_v1_9_3_125_/bin/ruby
versions/install-tags_v1_9_3_194_/bin/ruby
versions/install-tags_v1_9_3_195_/bin/ruby
versions/install-tags_v1_9_3_286_/bin/ruby
versions/install-tags_v1_9_3_327_/bin/ruby
versions/install-tags_v1_9_3_360_/bin/ruby
versions/install-tags_v1_9_3_362_/bin/ruby
versions/install-tags_v1_9_3_374_/bin/ruby
versions/install-tags_v1_9_3_385_/bin/ruby
versions/install-tags_v1_9_3_392_/bin/ruby
versions/install-tags_v1_9_3_429_/bin/ruby
versions/install-tags_v1_9_3_448_/bin/ruby
versions/install-tags_v1_9_3_preview1_/bin/ruby
versions/install-tags_v1_9_3_rc1_/bin/ruby
versions/install-tags_v2_0_0_0_/bin/ruby
versions/install-tags_v2_0_0_195_/bin/ruby
versions/install-tags_v2_0_0_247_/bin/ruby
versions/install-tags_v2_0_0_preview1_/bin/ruby
versions/install-tags_v2_0_0_preview2_/bin/ruby
versions/install-tags_v2_0_0_rc1_/bin/ruby
versions/install-tags_v2_0_0_rc2_/bin/ruby

And all of versions ignore the redefinition.
I implemented 1.9 VM as this behaviour because I think it is spec.

Could you ask matz?

----------------------------------------
Backport #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-42013

Author: gfx (Goro Fuji)
Status: Assigned
Priority: Normal
Assignee: nagachika (Tomoyuki Chikanaga)
Category: 
Target version: 


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/