Class: List
- Inherits:
-
Object
- Object
- List
- Defined in:
- lib/lib/list.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
Returns the value of attribute length.
Instance Method Summary collapse
- #add(item) ⇒ Object
-
#initialize ⇒ List
constructor
A new instance of List.
- #iterator ⇒ Object
Constructor Details
#initialize ⇒ List
Returns a new instance of List.
6 7 8 |
# File 'lib/lib/list.rb', line 6 def initialize @length = 0 end |
Instance Attribute Details
#length ⇒ Object
Returns the value of attribute length.
17 18 19 |
# File 'lib/lib/list.rb', line 17 def length @length end |
Instance Method Details
#add(item) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lib/list.rb', line 19 def add(item) x = [item] if @h == nil @h = x else @q[1] = x end @q = x @length+=1 end |
#iterator ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/lib/list.rb', line 30 def iterator return { h: @h, has_next: lambda { return @h != nil }, _next: lambda { return nil if @h == nil x = @h[0] @h = @h[1] return x }} end |