Class Array
In: util/aryzip.rb
Parent: Object

Array#car Array#cdr

Array#zip(array)

Methods
car    cdr    zip   
Public Instance methods
car()

Return first element of array

# File util/aryzip.rb, line 48
  def car()
    return first
  end
cdr()

Return all but first element of array. If it is more than one item, it is returned as an array, otherwise returned as an atom.

# File util/aryzip.rb, line 53
  def cdr()
    r = self[1..-1]
    r.size > 1 ? r : r.car
  end
zip(a2)

Joins two arrays together element by element, like a (physical) zipper, to create a combined array. If a is [ a, b ], and a2 is [ c, d ], then a.zip(a2) would return the array [ [a, c], [b, d ] ].

a2
Array to join to calling array.
# File util/aryzip.rb, line 63
  def zip(a2) 
    a = []
    each_index {
      |i| a.push(i < a2.size ? [self[i], a2[i]] : [self[i], a2.last])
    }
    return a
  end