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

#hObject

protected - in ruby this doesn’t play well with static/inline methods



12
13
14
# File 'lib/lib/list.rb', line 12

def h
  @h
end

#lengthObject

Returns the value of attribute length.



17
18
19
# File 'lib/lib/list.rb', line 17

def length
  @length
end

#qObject

Returns the value of attribute q.



13
14
15
# File 'lib/lib/list.rb', line 13

def q
  @q
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
# File 'lib/lib/list.rb', line 30

def iterator 
  ::X_List::ListIterator.new(@h)
end