From: 7stud -- Date: 2009-02-25T11:35:03+09:00 Subject: Re: Extrange String#=~ behaviour I単aki Baz Castillo wrote: > Hi, I can't understand it: > > class String > def =~ obj > puts "Sorry, I don't compare" > end > end > > b) 多? > irb> "string" =~ /string/ > 0 > > Could I know why case "b" perform the normal regexp comparission instead > of > invoking the re-defined String#=~ method?? > To me that suggests that String#=~ calls Regexp#=~. However, I am having no luck proving that. I can't even override Regexp#=~: class Regexp def =~(obj) puts "goodbye" end end puts /string/ =~ "string" #0 -- Posted via http://www.ruby-forum.com/.