From: Gunther Diemant Date: 2011-03-31T17:08:11+09:00 Subject: Re: How can I generate new variables? --0016e6dab13f647013049fc2c9b0 Content-Type: text/plain; charset=ISO-8859-1 2011/3/31 Kyle X. > > 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 --0016e6dab13f647013049fc2c9b0--