Class: List
- Inherits:
-
Collection
- Object
- Collection
- List
- Defined in:
- lib/list.rb
Overview
List class implementing a list collection
Instance Method Summary collapse
-
#initialize(size = nil) ⇒ List
constructor
A new instance of List.
-
#push(object) ⇒ Object
This method appends an element to the list.
-
#to_s ⇒ Object
Defines to string method.
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_s ⇒ Object
Defines to string method
25 26 27 |
# File 'lib/list.rb', line 25 def to_s @list end |