From: Martin DeMello Date: 2006-08-02T01:04:17+09:00 Subject: Re: Enumerable On 8/1/06, Michael Saltzman wrote: > Am new to Ruby and have the folloiwng Question. > > I have a class, say Collect, and I want to mixin Enumerable. How do I > write the each method in Collect? > > class Collect > include Enumerable > def initialize() > @array = Array.new(0) > @ct = 0 > end > def add(item) > @array.push(item) > @ct += 1 > end > def howmany > @ct > end > def each > # > # Not sure how to do this???? > # > end > end Assuming you want to iterate over @array, def each @array.each {|i| yield i} end martin