From: mortee Date: 2007-10-12T20:35:02+09:00 Subject: Re: Array += Simon Mullis wrote: >>> (a ||= []) << [1, 2, 3, 4] > => [[1, 2, 3, 4]] > > But > >>> ( a ||= [] ) += [ 1, 2, 3, 4 ] > SyntaxError: compile error > (irb):28: syntax error, unexpected tOP_ASGN, expecting $end > ( a ||= [] ) += [ 1, 2, 3, 4 ] > ^ > from (irb):28 > > Why? > > I guess it's a precedence issue. '<<' is a method in the Array class. > '+=' is not. The difference is that << is a method, += is an assignment. (a ||= []) returns an object, on which you can call a method, but you can't assign to. You can only assign to the a variable itself, which (a ||= []) is not. I guess. mortee