From: ahoward Date: 2002-11-15T05:40:58+09:00 Subject: Array#next - Enumerable#next ? rubyists- does anyone know a way to implement this generically for all enumerable objects in an efficient manner? class Array def next # start iterating if we never have before @itr = 0 unless @itr @itr = @itr.succ # if there are no more elements return nil # but also set itr back to zero so subsequent # calls to next will succeed if @itr > size @itr = 0 return nil end return self[@itr - 1] end end this is really usefull. if it could be done for any Enumerable object then something like this : module Kernel def concert(*enumerables, &block) args = enumerable.collect{|e| e.next} return if args.include? nil block.call *args end end h = {:answer => 42} a = [42] concert(h, a) do |k,v,a| puts k, v, a end would be *very* cool. also, this could be more generic than some of the methods being suggested for things like this... -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ahoward@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================