From: tamouse mailing lists Date: 2013-02-02T14:57:41+09:00 Subject: Re: Enumeration vs Enumerable On Fri, Feb 1, 2013 at 11:07 PM, Arup Rakshit wrote: > Calvin B. wrote in post #1094821: >> Hi, >> >> sorry if I confused you, I just repeated the definition (as I remembered >> it) without really explaining it. In the case of an array, the array is >> the enumeration AND the collection. There are some cases in which the >> two differ. An example which hopefully clears that up: The collection of >> all integers. Since the collection is infinite, we can't really have a >> list of all integers (at least as data). We could, in this specific >> case, describe our collection in a way so we can list an arbitrary >> number of elements, but never all. >> >> Regards, >> Calvin > > @calvin - Your example is good. But in this context with this example > how array is differing from enumerator? An Array is a class which includes the properties of Enumerable: 1.9.3-head :003 > Array.ancestors => [Array, Enumerable, Object, Kernel, BasicObject] If the class Array was implemented in pure Ruby (which it's not), it would look something like this: class Array include Enumerable # class definition and overrides for Enumerable methods as needed3 end The Enumerable class provides methods for many of the actions you normally take on an Array, such as :each, :sort, :count, :first, and so on. Other classes also include Enumerable; Hash, File, Dir, Range, etc.