I am just learning Ruby and I want to know the difference between
a += b and
a =+ b I am just learning Ruby and I want to know the difference between
a += b and
a =+ b a += b is syntactic shorthand for a = a + ba =+ b is similar to a = + bSo, 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.
foo += bar is shorthand for foo = foo + bar.foo =+ bar is an unusual way to write foo = +bar.+@ instance method should be defined on bar.class. For the former, the coercion from bar.class to foo.class is required.bar is a frozen string, then foo = +bar becomes a shorthand for foo = bar.dup, i.e. it assigns a mutable duplicate of the string to foo.