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
# File 'lib/lab42/list.rb', line 10

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

#caddrObject



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

def caddr = cdr.cdr.car

#cadrObject



16
# File 'lib/lab42/list.rb', line 16

def cadr = cdr.car

#cdddrObject



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

def cdddr = cdr.cdr.cdr

#cddrObject



20
# File 'lib/lab42/list.rb', line 20

def cddr = cdr.cdr

#cons(new_head) ⇒ Object



24
# File 'lib/lab42/list.rb', line 24

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

#deconstructObject



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

def deconstruct = [car, cdr]

#each(&blk) ⇒ Object



28
# File 'lib/lab42/list.rb', line 28

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty? = false