ElektroStudios
ElektroStudios

Reputation: 20464

Comparision of a regexp in ruby

I want to make a case sensitive comparision like this:

If ARGV[0].eql? /word/i
  print "yep! ^^"
elsif 
  print "nope :("
end

But that don't works... Don't recognizes "word" I've tryed too quoteing and escaping chars...

What i'm doing wrong?

Thankyou

Upvotes: 1

Views: 425

Answers (2)

Jakobinsky
Jakobinsky

Reputation: 1294

The problem is that you are trying to compare a regex to a string. By changing /word/i to 'word' it should work.

Upvotes: 1

Sergey
Sergey

Reputation: 11908

Probably you should use =~ operator, then

"word" =~ /word/i

works fine

http://www.regular-expressions.info/ruby.html

Upvotes: 4

Related Questions