How do you say not equal to in Ruby?

Ger Crowley picture Ger Crowley · Oct 3, 2011 · Viewed 123.6k times · Source

This is a much simpler example to what I'm trying to do in my program but is the similar idea. In an if statement how do I say say not equal to?

Is != correct?

def test
  vara = 1
  varb = 2
  if vara == 1 && varb != 3
    puts "correct"
  else
    puts "false"
  end
end

Answer

Rondel picture Rondel · Oct 3, 2011

Yes. In Ruby the not equal to operator is:

!=

You can get a full list of ruby operators here: https://www.tutorialspoint.com/ruby/ruby_operators.htm.