Question: How can I shorten this class method (currently 10 lines long)?

```
class DoubleSeries
  def self.generate_sequences(seq1_start, seq2_start, seq1_step, seq2_step, iterations)
    seq1,seq2=seq1_start,seq2_start
    result=[]
    (1..iterations).each do
      result << seq1 << seq2
      seq1+=seq1_step
      seq2+=seq2_step
    end 
    result
  end 
end

```

I tried doing:

```
class DoubleSeries
  def self.generate_sequences(seq1_start, seq2_start, seq1_step, seq2_step, iterations)
    seq1,seq2=seq1_start,seq2_start
    result=
    (1..iterations).each do
      self << seq1 << seq2
      seq1+=seq1_step
      seq2+=seq2_step
    end 
    result
  end 
end

```

but `self` is the class at this point (as this is a class method), not the `result=` variable.

Answer: 
You could a number of different things. For instance, using ranges and a couple of Array methods, I get this:

```
class DoubleSeries
  def self.generate_sequences(seq1_start, seq2_start, seq1_step, seq2_step, iterations)
    seq1_end = seq1_start + iterations * seq1_step
    seq2_end = seq2_start + iterations * seq2_step
    seq1 = (seq1_start..seq1_end).step(seq1_step)
    seq2 = (seq2_start..seq2_end).step(seq1_step)
    seq1.zip(seq2)
  end
end

```

There's still some nasty repetition going on. I might suggest simply skipping all this in favor of a `generate_sequence` method, that only returns a single sequence. Then you can use that plus `Array#zip` to generate double, triple, or whatever sequences:

```
def generate_sequence(start, step, iterations)
  limit = start + iterations * step
  (start..limit).step(step).to_a
end

double_seq = generate_sequence(a, b, c).zip(generate_sequence(x, y, z))

```
I would be inclined to write it like this:

```
class DoubleSeries
  class << self
    def generate_sequences(seq1, seq2, iterations)
      s1 = sequence(seq1, iterations)
      s2 = sequence(seq2, iterations)
      s1.zip(s2)
    end

    private

    def sequence(seq, iterations)
      rng = (seq[:start]..seq[:start]+seq[:step]*(iterations-1))
      rng.step(seq[:step]).reduce([]) {|arr, i| arr << i}
    end  
  end
end

seq1 = {start: 1, step: 2}
seq2 = {start: 4, step: 3}
DoubleSeries.generate_sequences(seq1, seq2, 5)
  # => [[1, 4], [3, 7], [5, 10], [7, 13], [9, 16]] 

```

I trust you don't mind that I've taken the liberty of changing the arguments a little. A couple of notes:

* I prefer making all the changes in the class's metaclass, hence the `class << self / end` wrapper. This allows one to write code in the same way that one would for class instances, including (class) instance variables (@a), local variables, instance methods, getters and setters for (metaclass) instance variables, and so on. Notice that there is no `self.` in defining class instance methods. That's because self equals the metaclass when those methods are constructed.
* For the example values I have given for seq1 and seq2, sequence(seq1, 5) => [1, 3, 5, 7, 9] and sequence(seq2, 5) => [4, 7, 10, 13, 16]. These are zipped together to construct the desired sequence.