sample/list3.rb


DEFINITIONS

This source file includes following functions.


   1  # Linked list example -- short version
   2  # using inspect
   3  
   4  class Point
   5    def initialize(x, y)
   6      @x = x; @y = y
   7      self
   8    end
   9  
  10    def to_s
  11      sprintf("%d@%d", @x, @y)
  12    end
  13  end
  14      
  15  list1 = [10, 20, Point.new(2, 3), Point.new(4, 5)]
  16  list2 = [20, Point.new(4, 5), list1]
  17  print("list1: ", list1.inspect, "\n")
  18  print("list2: ", list2.inspect, "\n")