D
Dave Lenhardt
Hey, another question. This is kinda putting several concepts together
that i understand but the code is throwing me for some reason:
class Periods
def each
yield "Classical"
yield "Jazz"
yield "Rock"
end
end
periods = Periods.new
for genre in periods
print genre, " "
end
produces:
Classical Jazz Rock
So a simple for..in loop which is the same as using the .each for an
array/Hash, etc.
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?
that i understand but the code is throwing me for some reason:
class Periods
def each
yield "Classical"
yield "Jazz"
yield "Rock"
end
end
periods = Periods.new
for genre in periods
print genre, " "
end
produces:
Classical Jazz Rock
So a simple for..in loop which is the same as using the .each for an
array/Hash, etc.
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?