Considering the slower approachs they could lead you to a code like this ...

class Point
  def initialize(x,y)
    @x, @y = x, y
  end

  def self.[](x,y)
     new(x,y)
  end

  def +(offset)
     @x += offset
     @y += offset
  end
end

p1 = Point[10,20]
p2 = Point[30,40]

[p1, p2].each { |p| p += 1}

Or you can go futher writing a class called PointCollection ...

And have something like ...

pc = PointCollection.new(p1, p2)

pc.increment_all_by(1)

And you can go on... to infinite and beyond...

But, I think your first example is just right (since you use it with
only 4 variables (not 100)).

Abinoam Jr.

On Wed, Nov 6, 2013 at 9:12 PM, Stefan Salewski <mail / ssalewski.de> wrote:
> 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?
>
>