From: Peter Hickman Date: 2001-11-30T21:24:26+09:00 Subject: [ruby-talk:27054] Using Enumerable Im trying to write my own each method for a 'sort of' range class that gets its data from a file (but will have to process it before passing it on). The following bit of code fails! Just how do you write an each method? #!/usr/local/bin/ruby def testing(f) print " First...\n" f.each {|n| print " #{n}\n" } print " Second...\n" f.each {|n| print " #{n}\n" if n == 5 then break end } end class Fred include Enumerable def initialize @end = 10 @pointer = 0 end def each if @pointer == @end then return nil else @pointer += 1 return @pointer end end end print "Using a range...\n" f = (1..10) testing(f) print "Our new class...\n" f = Fred.new testing(f)