From: ahoward Date: 2002-11-28T01:11:37+09:00 Subject: Re: each_with_index & collect_with_index? On Wed, 27 Nov 2002, Tim Bates wrote: T> arr.each do |e| T> outerindex = Enumerable.index T> arr.each do |f| T> innerindex = Enumerable.index T> ... T> end T> end this is all very straight forward using an Enumerable::Iterator, i had to add only two lines to the class to accomplish this : arr = %w(zero one two) a = arr.iterator a.each do |ea| print "a.index(#{a.index}) -> ea : #{ea}\n\t" b = arr.iterator b.each do |eb| print "b.index(#{b.index}) -> eb : #{eb}, " end print "\n" end >> a.index(0) -> ea : zero b.index(0) -> eb : zero, b.index(1) -> eb : one, b.index(2) -> eb : two, a.index(1) -> ea : one b.index(0) -> eb : zero, b.index(1) -> eb : one, b.index(2) -> eb : two, a.index(2) -> ea : two b.index(0) -> eb : zero, b.index(1) -> eb : one, b.index(2) -> eb : two, http://eli.fsl.noaa.gov/lib/ruby/site_ruby/1.6/enumerable.rb -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 ====================================