From: daz Date: 2005-08-01T20:21:03+09:00 Subject: Re: Redefining Regexp#=== Pit Capitain wrote > Hi, > > what's wrong with this code: > > class Regexp > alias :case_eq :=== > def ===( other ) > case_eq( other ) > end > end > > p( /x/ === "abxy" ) # => true > p( Regexp.last_match ) # => nil > p( /x/.case_eq( "abxy" ) ) # => true > p( Regexp.last_match ) # => # > > Why is Regexp.last_match not set when calling the redefined method? > This is ruby 1.8.2 (2004-12-25) [i386-mswin32] on Windows 2000. Hi Pit, Regexp#=== is an alias for =~ , therefore need to alias both, I think: class Regexp alias :case_eq :=~ alias :case_eq :=== def =~( other ) case_eq( other ) end end p( /x/ === "abxy" ) # => true p( Regexp.last_match ) # => # p( /x/.case_eq( "abxy" ) ) # => true p( Regexp.last_match ) # => # You'll know what to do :-) Regards, daz