Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby: How do you say not equal to in Ruby?

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

Is != correct?

def test   vara = 1   varb = 2   if vara == 1 && varb != 3     puts "correct"   else     puts "false"   end end 
like image 448
Ger Crowley Avatar asked Oct 03 '11 13:10

Ger Crowley


People also ask

What does |= mean in Ruby?

Ruby has an or-equals operator that allows a value to be assigned to a variable if and only if that variable evaluates to either nil or false .

How do you say not equal in code?

The not-equal-to operator ( != ) returns true if the operands don't have the same value; otherwise, it returns false .

What is << in Ruby on Rails?

It lets you add items to a collection or even concatenate strings.


1 Answers

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.

like image 64
Rondel Avatar answered Sep 20 '22 23:09

Rondel