From: Brian Candler Date: 2009-11-23T07:02:13+09:00 Subject: Re: Newbie question: Enumerators Omran Nazir wrote: > What sort of objects can be defined as > 'enumerable' and what makes them so? Something is enumerable if it implements a method (conventionally called "each") which yields a series of values into a block. If you mix in the Enumerable module then you get a whole bunch of additional methods which build on this - select, map, min/max, sort_by etc. Each of those method just calls your "each" method and then processes the values yielded. > Can someone please give a simple explantion of what exactly an > Enumerator is, what it can act on and why you can pass 'array.to_enum' > to a method that expect 'array'? As it happens, someone asked me to write this up a few days ago. The result is here: http://wiki.github.com/rdp/ruby_tutorials_core/enumerator It's not something that most people need. The most common use is when you want to use the Enumerable methods but iterate using a method other than 'each', for example 'each_byte' or 'each_with_index' -- Posted via http://www.ruby-forum.com/.