From: Kurtis Rainbolt-greene on
irb(main):001:0> x = 2
=> 2
irb(main):002:0> y = 4
=> 4
irb(main):003:0> x, y *= 2
SyntaxError: (irb):3: syntax error, unexpected tOP_ASGN, expecting '='
x, y *= 2
^
from /usr/local/bin/irb:12:in `<main>'


:(
--
Posted via http://www.ruby-forum.com/.

From: Alex DeCaria on
Kurtis Rainbolt-greene wrote:
> irb(main):001:0> x = 2
> => 2
> irb(main):002:0> y = 4
> => 4
> irb(main):003:0> x, y *= 2
> SyntaxError: (irb):3: syntax error, unexpected tOP_ASGN, expecting '='
> x, y *= 2
> ^
> from /usr/local/bin/irb:12:in `<main>'
>
>
> :(

You need the same number of arguments on the right hand side as you do
on the left. For example,

x, y = 3

print x, y => 3, nil

x, y = 3, 3

print x, y => 3, 3
--
Posted via http://www.ruby-forum.com/.

From: Kurtis Rainbolt-greene on
Alex DeCaria wrote:

> compound assignment operators such as *=, +=, etc. aren't allowed
> with parallel assignment.

Ah-ha, someone gets what I was talking about, but my point was they
should be allowed. "Path of least surprise" and all that, plus this
looks cleaner:

x, y, z = 2, 4, 6

x, y += z

than

x, y, z = 2, 4, 6

x += z
y += z
--
Posted via http://www.ruby-forum.com/.

From: Alex DeCaria on
>
> You need the same number of arguments on the right hand side as you do
> on the left. For example,
>
> x, y = 3
>
> print x, y => 3, nil
>
> x, y = 3, 3
>
> print x, y => 3, 3

And, compound assignment operators such as *=, +=, etc. aren't allowed
with parallel assignment.

--
Posted via http://www.ruby-forum.com/.

From: Gavin Sinclair on
> should be allowed. "Path of least surprise" and all that, plus this
> looks cleaner:
>
> x, y, z = 2, 4, 6
>
> x, y += z


I have no idea what that code snippet is intended to do! So it
doesn't look cleaner to me.

Gavin
 |  Next  |  Last
Pages: 1 2 3
Prev: * splat error
Next: Calculation in a block