From: "S. Robert James" Date: 2007-02-24T06:25:06+09:00 Subject: Re: enum_cons with tail I'm not sure how to do either of those. Like I said, this is a File, not a true Array. (The magic of Ruby makes it Enumerable, but I haven't mastered that magic yet.) On Feb 23, 3:54 pm, "Kenosis" wrote: > On Feb 23, 11:50 am, "S. Robert James" wrote: > > > > > enum_cons chops off the tail of the collection, if it isn't evenly > > divisble: > > > e.g.: > > (1..10).each_cons(3) {|a| p a} > > # outputs below > > [1, 2, 3] > > [2, 3, 4] > > [3, 4, 5] > > [4, 5, 6] > > [5, 6, 7] > > [6, 7, 8] > > [7, 8, 9] > > [8, 9, 10] > > > I'd also like to get: > > [9, 10, nil] > > [10, nil, nil] > > > Is there anyway to do this? (The collection is an opened File, too > > large to load entirely in memory.) > > > I don't have a clear grasp as to how internally Ruby treats a File as > > Enumerable. > > Not that I am aware of. Two things come to mind. 1) You could append > nil items to your array to make it evenly divisable, 2) you could > extend arrary with your own each_cons that does what you want. Hope > this is at least some help. Perhaps others will know a more direct > way to accomplish what you seek. > > Ken