Class: X_List::ListIterator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(head) ⇒ ListIterator

Returns a new instance of ListIterator.



7
8
9
10
# File 'lib/lib/x_list/list_iterator.rb', line 7

def initialize(head)
  @head = head
  @val = nil
end

Instance Attribute Details

#headObject

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



14
15
16
# File 'lib/lib/x_list/list_iterator.rb', line 14

def head
  @head
end

#valObject

Returns the value of attribute val.



15
16
17
# File 'lib/lib/x_list/list_iterator.rb', line 15

def val
  @val
end

Instance Method Details

#_nextObject



23
24
25
26
27
# File 'lib/lib/x_list/list_iterator.rb', line 23

def _next 
  @val = @head[0]
  @head = @head[1]
  @val
end

#has_nextObject



19
20
21
# File 'lib/lib/x_list/list_iterator.rb', line 19

def has_next 
  @head != nil
end