Stefan Salewski wrote in post #1126646:
> I am doing some calculations, which often includes adding some offset to
> a few values, i.e. moving a line segment (x1, y1, x2, y2).
> Storing the values in an array makes not really sense, I don't want to
> write coord[0][1] instead of y1.
>
> So I have a few statements like
>
> a, b, c, d = a + o, b + o, c + o, d + o
>
> I can replace that with
>
> a, b, c, d = [a, b, c, d].map{|x| x + o}
>
> which is slower, but "cleaner" in my opinion.
> Is there another solution?

I think there's nothing wrong with writing

  a += o
  b += o
  c += o
  d += o

as an alternative to the first statement, it lines up vertically and 
it's clear on a row-by-row basis what is happening to each variable;  it 
depends entirely on your tastes.

Anything you do to write it more succinctly will almost certainly be 
slower.

If ruby were more of a lisp, I could imagine that something like this 
could be optimised in the compiler:

  (a, b, c, d).map!{|x| x + o }

but it's not, and it isn't.

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