Method: Cons#length

Defined in:
lib/cons.rb

#lengthObject Also known as: list_length



70
71
72
73
74
75
76
77
78
# File 'lib/cons.rb', line 70

def length
  result = 0
  current = self
  while current and current.car and not current.car.nil?
    result += 1
    current = current.cdr
  end
  result
end