in [Ruby]

Prev: * splat error
Next: Calculation in a block
From: Kurtis Rainbolt-greene on 4 May 2010 06:43 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 4 May 2010 07:18 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 4 May 2010 07:31 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 4 May 2010 07:20 > > 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 4 May 2010 08:05
> 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 |