From: Jan Svitok Date: 2006-10-13T06:43:10+09:00 Subject: Re: match with string instead of regexp fails On 10/12/06, Cameron, Gemma (UK) wrote: > > I thought the syntax was incorrect.... > > "cat" =~ "a" #=> 1 > > Fails as it's looking to match a reg ex not a string. > > Should be: > > "cat" =~ /a/ #=> 1 > > Or am I wrong?!?! Indeed, the example *is* wrong (judged by current ruby). However the documentation states that: str =~ obj => fixnum or nil Match� If obj is a String, look for it in str (similar to String#index). Returns the position the match starts, or nil if there is no match. Otherwise, invokes obj.=~, passing str as an argument. The default =~ in Object returns false. "cat o' 9 tails" =~ '\d' #=> nil (http://ruby-doc.org/core/classes/String.html#M001453) The question was why it doesn't work. The answer: the online documentation is outdated (I don't know how the docs in the install package look like, I haven't installed 1.8.5 yet).