Newbie question on regexp in a class method

trying regexp in ruby for the first time. the results from the
following code confuses me.


require 'B'

def Localmatch(t,s)
  myS =
  if t =~ myS
    puts "'#{s}' matches '#{t}'"
    puts "'#{s}' does not match '#{t}'"

myB =

puts "Using a class method to match"
myB.Matchme("The Lord of the Ring", "Ring")
myB.Matchme("No more than one", "King")
puts "Let's try local def"
Localmatch("The Lord of the Ring", "Ring")
Localmatch("No more than one", "King")

class B

def initialize

def Matchme(t,stringToMatch)
  mystr =
  if title =! mystr
    puts "'#{stringToMatch}' matches '#{t}'"
    return true
    puts "'#{stringToMatch}' does not match '#{t}'"
    return false


In the class method, "Ring" is not matching the text "The Lord of the
Ring" while in the local def it is. What am i doing wrong?
Posted via

Rick Tan wrote:

if title =! mystr

=! != =~
The above might look like line noise but should tell you everything you need
to know :wink:



NP: Depeche Mode - John The Revelator
ICQ: 205544826