# class that is similar to the built-in Range class class MyRange @@count = 0 # class variable to count # of objects constructed def initialize(first = 0, last = 10) @first = first @last = last @@count += 1 end def count return @@count end def each i = @first while i <= @last yield i i += 1 end end attr_reader :first, :last attr_writer :first, :last def to_s return "#{@first}..#{@last}" end # without attr_reader and attr_writer, we would have done something like this # def first # return @first # end # # def first=(n) # @first = n # end end