Topic: Simple operator question

Is there a difference between the append operator '<<' and the '+=' operator?

I have an array and I'm adding to it, I've used both before, but I'm trying to understand if there is a difference between the two or if it's just repetitive.

I just want to make sure I'm not missing anything here.

Last edited by RailsRhino (2010-08-17 15:41:00)

- Ben

Re: Simple operator question

Usually we add an object to an Array with '<<' operator.

Append—Pushes the given object on to the end of this array. This expression returns the array itself, so several appends may be chained together.

As for '+=' operator, officially it is not on the Arrays method list, So, personally, I never used it and I'd avoid using it.
By the way there is one more operator for Array: '+' but here is what is for:

Concatenation—Returns a new array built by concatenating the two arrays together to produce a third array.

Re: Simple operator question

actually I believe I used the '+=' for something else and though I did for an array, who knows. Either way, I have been using '<<' and works fine. In theory, they both seem to do practically the same thing though so I was confused but I think, like you said, the operators are for different things.

Thanks!

Last edited by RailsRhino (2010-08-17 16:50:13)

- Ben