Operadores en Ruby

Asignacion

a = 1
a += 1
a -= 1
a *= 1
a /= 1

 

Encadenacion de Asignaciones

a = b = 1 + 2 + 3
puts "a= #{a}"    #a=6
puts "b= #{b}"    #b=6

a = (b=1+2) + 3
puts "a= #{a}"    #a=6
puts "b= #{b}"    #b=3

 

Asignacion Paralela

a=1
b=2

a,b = (a+b),a

puts "a= #{a}"  #a=3
puts "b= #{b}"  #b=1

 

x = 0

a,b,c = x,(x+=1),(x+=1)

puts "a= #{a}"    #0
puts "b= #{b}"    #1
puts "c= #{c}"    #2

 

Comparación

a = 2
b = 2

a == 2 //true
a == 3 //false

a == a //true
a == b //true

a != 2 //false
a != 3 //true
a != a //false

a < b //false
a <= b // true
a > b //false 
a >= b // true