From: "Mauricio Fernández" Date: 2005-08-02T01:36:38+09:00 Subject: Re: Redefining Regexp#=== On Tue, Aug 02, 2005 at 12:51:06AM +0900, daz wrote: > > I wrote: > > > > > Regexp#=== is an alias for =~ , therefore need to alias both, I think: > > > > > Sorry folks. I fooled myself with a plausible-looking test :-( > > Pit's question is still open. batsman@tux-chan:/tmp$ cat wrapre.rb require 'binding_of_caller' class Regexp alias_method :case_eq, :=== def ===(other) Binding.of_caller do |b| case_eq(other) eval("lambda{|x| $~ = x}", b).call($~) nil != $~ end end end # former results... p(/x/ === "abxy") # => true p(Regexp.last_match) # => nil p(/x/.case_eq("abxy")) # => true p(Regexp.last_match) # => # batsman@tux-chan:/tmp$ ruby wrapre.rb true # true # -- Mauricio Fernandez