From: "Thomas B." Date: 2008-09-21T06:51:55+09:00 Subject: Re: Explaination of a bit of code Dave Lenhardt wrote: > I guess I am having trouble thinking how this would work out. Each is > suppose to go through a set of items. however, where are the items? I > see three strings but they are used in yield statements. How is this > method actually working? The method each is working just as you programme it. For Arrays (and Enumerables, in general) it calls the passed block with each element of the object (self) in turn, so in some useless pseudocode, Array#each works like this: for each element of self in e yield(e) end Now you can see that your own each works just like ["Classical","Jazz","Rock"].each{|e| yield(e)} So, your Periods::new works like the array ["Classical","Jazz","Rock"] itself. Only your object is a dummy array - it does not read the elements from any kind of set or anything, it is just hardcoded to call yield with these three strings. But from outside you cannot tell your Period::new from ["Classical","Jazz","Rock"], they just behave in the same way when we call the method each on them. And that's why the for loop sees your object as if it was the array of the three strings. TPR. -- Posted via http://www.ruby-forum.com/.