Array#car Array#cdr
- Just like the lisp operations car and cdr.
Array#zip(array)
- "Zips" two arrays together to make one returned array.
Return first element of array
# File util/aryzip.rb, line 48
def car()
return first
end
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
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