From: Robert Klemme Date: 2005-08-29T18:10:19+09:00 Subject: Re: [Q] how to unflatten a flat-array 2005/8/29, SHIGETOMI, Takuhiko : > greetings, Robert. thank you, it does make sense to me. > > > >> res=[]; 0.step(a.length - 1,2) {|i| res << [a[i],a[i+1]]}; res > > => [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]] > > i know that an yieldee is 100% passive to its yielder, but i often feel > desire to let it fetch to the next/previous yielded object from inside > the yieldee. > > don't you know any cool way to do this in ruby? No, not generally. With arrays you can use #each_with_index and in the general case of Enumerable you can use inject to access the last element, along the lines enum.inject {|last, current| .... ; current} Kind regards robert