diff options
Diffstat (limited to 'sample/list.rb')
| -rw-r--r-- | sample/list.rb | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/sample/list.rb b/sample/list.rb index 85899ce7ff..7458ba0244 100644 --- a/sample/list.rb +++ b/sample/list.rb @@ -5,7 +5,6 @@ class MyElem # @variables are instance variable, no declaration needed @data = item @succ = nil - @head = nil end def data @@ -23,6 +22,10 @@ class MyElem end class MyList + def initialize + @head = nil + end + def add_to_list(obj) elt = MyElem.new(obj) if @head @@ -76,6 +79,6 @@ $list2.add_to_list(20) $list2.add_to_list(Point.new(4, 5)) $list2.add_to_list($list1) -# parenthesises around method arguments can be ommitted unless ambiguous. +# parenthesises around method arguments can be omitted unless ambiguous. print "list1:\n", $list1, "\n" print "list2:\n", $list2, "\n" |
