From: David Alan Black Date: 2001-11-30T23:13:09+09:00 Subject: [ruby-talk:27065] Re: Using Enumerable On Fri, 30 Nov 2001, David Alan Black wrote: > Hi -- > > On Fri, 30 Nov 2001, Peter Hickman wrote: > > > Thanks to all who replied, like all ruby it was alot simpler than I > > thought. > > > > class Fred > > include Enumerable > > > > def initialize > > @end = 10 > > @pointer = 0 > > end > > > > def each > > while @pointer != @end do > > @pointer += 1 > > yield @pointer > > end > > @pointer = 0 > > end > > end > > And if you want to be even more concise while still (in my opinion :-) > being readable: > > def each > yield @pointer += 1 until @pointer == @end > @pointer = 0 > end > > Or even: def each yield *@pointer + 1 .. @end end One of the things I love about Ruby is how as you work on a problem, the code sort of evaporates off the screen bit by bit :-) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav