# Linked list example class MyElem # object initializer called from Class#new def initialize(item) # @variables are instance variable, no declaration needed @data = item @succ = nil @head = nil end def data @data end def succ @succ end # the method invoked by ``obj.data = val'' def succ=(new) @succ = new end end class MyList def add_to_list(obj) elt = MyElem.new(obj) if @head @tail.succ = elt else @head = elt end @tail = elt end def each elt = @head while elt yield elt elt = elt.succ end end # the method to convert object into string. # redefining this will affect print. def to_s str = "