Class: List

Inherits:
Object
  • Object
show all
Defined in:
lib/lib/list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeList

Returns a new instance of List.



6
7
8
# File 'lib/lib/list.rb', line 6

def initialize
  @length = 0
end

Instance Attribute Details

#lengthObject

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

#iteratorObject



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