Class: Lab42::List

Inherits:
Object
  • Object
show all
Extended by:
ClassMethods
Includes:
Enumerable
Defined in:
lib/lab42/list.rb,
lib/lab42/list/class_methods.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ClassMethods

list?, new

Instance Attribute Details

#carObject (readonly)

Returns the value of attribute car.



8
9
10
# File 'lib/lab42/list.rb', line 8

def car
  @car
end

#cdrObject (readonly)

Returns the value of attribute cdr.



8
9
10
# File 'lib/lab42/list.rb', line 8

def cdr
  @cdr
end

#lengthObject (readonly)

Returns the value of attribute length.



8
9
10
# File 'lib/lab42/list.rb', line 8

def length
  @length
end

Instance Method Details

#==(other) ⇒ Object



10
11
12
13
14
15
# File 'lib/lab42/list.rb', line 10

def ==(other)
  self.class.list?(other) &&
    length == other.length &&
    car == other.car &&
    cdr == other.cdr
end

#caddrObject



21
22
23
# File 'lib/lab42/list.rb', line 21

def caddr
  cdr.cdr.car
end

#cadrObject



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

def cadr
  cdr.car
end

#cdddrObject



29
30
31
# File 'lib/lab42/list.rb', line 29

def cdddr
  cdr.cdr.cdr
end

#cddrObject



25
26
27
# File 'lib/lab42/list.rb', line 25

def cddr
  cdr.cdr
end

#cons(new_head) ⇒ Object



33
34
35
# File 'lib/lab42/list.rb', line 33

def cons(new_head)
  self.class.cons(new_head, self)
end

#deconstructObject



37
38
39
# File 'lib/lab42/list.rb', line 37

def deconstruct
  [car, cdr]
end

#each(&blk) ⇒ Object



41
42
43
# File 'lib/lab42/list.rb', line 41

def each(&blk)
  self.class.each(self, &blk)
end

#empty?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/lab42/list.rb', line 45

def empty?
  false
end