From: Daniel DeLorme Date: 2007-02-28T20:57:22+09:00 Subject: Re: How can I monitor a Regexp? Jan Friedrich wrote: > ruby -v > # ==> ruby 1.8.4 (2005-12-24) [i486-linux] > > class String; def =~(o); raise "S"; end; end > class Regexp; def =~(o); raise "R"; end; end > > r = /x/ > r =~ 'a' > # ==> RuntimeError: R > from (irb):2:in `=~' > from (irb):4 > 'a' =~ r > # ==> RuntimeError: S > from (irb):1:in `=~' > from (irb):5 Very interesting. If you assign the regexp to a variable you get the overridden methods. I guess there's some voodoo optimization at work when you use =~ on a regexp literal? Daniel