Class: List

Inherits:
Collection show all
Defined in:
lib/list.rb

Overview

List class implementing a list collection

Direct Known Subclasses

QueueList, Stack

Instance Method Summary collapse

Constructor Details

#initialize(size = nil) ⇒ List

Returns a new instance of List.



7
8
9
10
11
# File 'lib/list.rb', line 7

def initialize(size = nil)
  super()
  @list = Array.new
  @size = size
end

Instance Method Details

#push(object) ⇒ Object

This method appends an element to the list



15
16
17
18
19
20
21
# File 'lib/list.rb', line 15

def push(object)
  if(@size && @list.length >= @size)
    raise CollectionErrors::ListOverflowError.new
  else
    @list.push(object)
  end
end

#to_sObject

Defines to string method



25
26
27
# File 'lib/list.rb', line 25

def to_s
  @list
end