Hi, At Sat, 26 Sep 2009 14:44:17 +0900, Nobuyoshi Nakada wrote in [ruby-core:25789]: > At Sat, 26 Sep 2009 10:57:19 +0900, > Tanaka Akira wrote in [ruby-core:25782]: > > I think Enumerator.new (and possibly to_enum, enum_for) > > should be able to take an array consists of two method names > > for internal and external iteration as: > > Enumerator.new(obj, [method1, method2], *args) > > method1 is for internal iteration and method2 is for > > external iteration. The enumerator created by > > Enumerator.new uses method2 when next method is called if > > method2 is provided. obj.method2 should return an object > > for external iteration. > > Interesting. Forgot benchmark. $ ./ruby -rbenchmark -e 'Benchmark.bm{|bm| bm.report {100.times{f = File.new("eval.c"); while f.gets; end}} bm.report {100.times{f = File.new("eval.c").to_enum; loop {f.next}}} }' Before: user system total real 0.120000 0.010000 0.130000 ( 0.135900) 0.670000 0.010000 0.680000 ( 0.699996) After: user system total real 0.120000 0.000000 0.120000 ( 0.131847) 0.190000 0.010000 0.200000 ( 0.205275) -- Nobu Nakada