M
Michael Saltzman
Am new to Ruby and have the folloiwng Question.
I have a class, say Collect, and I want to mixin Enumerable. How do I
write the each method in Collect?
class Collect
include Enumerable
def initialize()
@array = Array.new(0)
@ct = 0
end
def add(item)
@array.push(item)
@ct += 1
end
def howmany
@ct
end
def each
#
# Not sure how to do this????
#
end
end
I have a class, say Collect, and I want to mixin Enumerable. How do I
write the each method in Collect?
class Collect
include Enumerable
def initialize()
@array = Array.new(0)
@ct = 0
end
def add(item)
@array.push(item)
@ct += 1
end
def howmany
@ct
end
def each
#
# Not sure how to do this????
#
end
end