I've heard =+ is the same as a = a + b, and += is like "add a to b and return a" or something of that sort, but it's really confusing me how similar the two are. Could someone could explain the difference to me?
2 Answers
What's the difference between
+=and=+in ruby?
This question is non-sensical, since there is no such thing as =+ in Ruby. It doesn't make sense to ask about the difference between two things when one of those two things doesn't exist.
The only sensible difference between += and =+ in Ruby is that += exists and =+ doesn't.
1 Comment
David Venegas
Oh wow, well that's good to know. I'm just breaking into ruby, and I was learning += and thought I saw =+ and couldn't find the difference on google or anywhere, in relation to ruby anyway.. this explains it. Thank you kind sir
=+isn't one operator. It's the normal assignment operator followed by unary plus.a =+ bis the same asa = +b, which is the same asa = bunlessbhas a weirdly overloaded unary+operator.a=b*3+1writea = b * 3 + 1.