Class: Lab42::List
- Inherits:
-
Object
- Object
- Lab42::List
- 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
-
#car ⇒ Object
readonly
Returns the value of attribute car.
-
#cdr ⇒ Object
readonly
Returns the value of attribute cdr.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #caddr ⇒ Object
- #cadr ⇒ Object
- #cdddr ⇒ Object
- #cddr ⇒ Object
- #cons(new_head) ⇒ Object
- #deconstruct ⇒ Object
- #each(&blk) ⇒ Object
- #empty? ⇒ Boolean
Methods included from ClassMethods
Instance Attribute Details
#car ⇒ Object (readonly)
Returns the value of attribute car.
8 9 10 |
# File 'lib/lab42/list.rb', line 8 def car @car end |
#cdr ⇒ Object (readonly)
Returns the value of attribute cdr.
8 9 10 |
# File 'lib/lab42/list.rb', line 8 def cdr @cdr end |
#length ⇒ Object (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 |
#caddr ⇒ Object
21 22 23 |
# File 'lib/lab42/list.rb', line 21 def caddr cdr.cdr.car end |
#cadr ⇒ Object
17 18 19 |
# File 'lib/lab42/list.rb', line 17 def cadr cdr.car end |
#cdddr ⇒ Object
29 30 31 |
# File 'lib/lab42/list.rb', line 29 def cdddr cdr.cdr.cdr end |
#cddr ⇒ Object
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 |
#deconstruct ⇒ Object
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
45 46 47 |
# File 'lib/lab42/list.rb', line 45 def empty? false end |