0

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
  • 5
    =+ isn't one operator. It's the normal assignment operator followed by unary plus. a =+ b is the same as a = +b, which is the same as a = b unless b has a weirdly overloaded unary + operator. Commented Jul 4, 2021 at 0:50
  • The confusion at the base of this question is a pretty good argument for using whitespace around operators, even when the language doesn't strictly require it. Instead of a=b*3+1 write a = b * 3 + 1. Commented Jul 4, 2021 at 20:36

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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
1

There is no operator like =+ in ruby. If you are doing a =+ 1 when the value of a is 1. it always returns 1. but, if you are doing a += 1 it will return 2. you can't increment/decrement with =+.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.