2011/3/31 Kyle X. <haebooty / yahoo.com>

>
> I am writing this for SketchUP so I am using Ruby 1.8.6 and am having an
> issue with require 'enumerator', as it does not exist in their library
> as far as I can tell --- in turn the "each_slice" command does not
> function.
>
> Then you must write your own version. For example
def slice(array, chunk_size)
  result = []
  array.each_with_index do |element, index|
    result << [] if index % chunk_size == 0
    result.last << element
  end

  result
end

arr = [1,2,3,4,5,6]
slice(arr,2)   #=> [[1,2],[3,4],[5,6]]

I was wondering if you could help me understand this command better as
> well.  "data.each_slice(3) do |triplet|"  The "(3)" here means slice
> after 3 entries in data correct?  The word triplet used, is this word
> required or could it be any word as long as it is consistent below i.e.
> :  do |x| master_arr << x?  Sorry for the basic question, but I just
> want to clarify.
>
> Your right. You can call the thing triplet, x or chunky_bacon. Its just a
name for a local variable.

--
gd