module MoreCoreExtensions::ArrayStretch::ClassMethods

Public Instance Methods

stretch(*arys) click to toggle source

Stretch all argument Arrays to make them the same size.

Array.stretch([1, 2], [3, 4], [5, 6, 7])  #=> [[1, 2, nil], [3, 4, nil], [5, 6, 7]]
# File lib/more_core_extensions/core_ext/array/stretch.rb, line 7
def stretch(*arys)
  self.stretch!(*arys.collect { |a| a.dup })
end
stretch!(*arys) click to toggle source

Stretch all argument Arrays to make them the same size. Modifies the arguments in place.

Array.stretch!([1, 2], [3, 4], [5, 6, 7])  #=> [[1, 2, nil], [3, 4, nil], [5, 6, 7]]
# File lib/more_core_extensions/core_ext/array/stretch.rb, line 14
def stretch!(*arys)
  max_size = arys.collect { |a| a.length }.max
  arys.each { |a| a[max_size - 1] = nil unless a.length == max_size }
  return *arys
end