YouKnowWhatScrewThis YouKnowWhatScrewThis - 1 month ago 7
Ruby Question

What is the difference between += and =+ in Ruby?

I am just learning Ruby and I want to know the difference between

a += b


and

a =+ b

Answer Source
  1. a += b is syntactic shorthand for a = a + b
  2. a =+ b is similar to a = + b

So, firstValue = firstValue + secondValue is the same as firstValue = firstValue.+(secondValue) in ruby. firstValue + = secondValue – increment Add the value of secondValue to the value of firstValue , store the result in firstValue, and return the new value.