Class: Yadriggy::SourceCode::Cons
- Inherits:
-
Object
- Object
- Yadriggy::SourceCode::Cons
- Includes:
- Enumerable
- Defined in:
- lib/yadriggy/source_code.rb
Instance Attribute Summary collapse
-
#head ⇒ Object
Returns the value of attribute head.
-
#tail ⇒ Object
Returns the value of attribute tail.
Class Method Summary collapse
Instance Method Summary collapse
- #each ⇒ Object
- #fold(acc) ⇒ Object
-
#initialize(head, tail = nil) ⇒ Cons
constructor
A new instance of Cons.
- #size ⇒ Object
Constructor Details
#initialize(head, tail = nil) ⇒ Cons
Returns a new instance of Cons.
112 113 114 115 |
# File 'lib/yadriggy/source_code.rb', line 112 def initialize(head, tail=nil) @head = head @tail = tail end |
Instance Attribute Details
#head ⇒ Object
Returns the value of attribute head.
110 111 112 |
# File 'lib/yadriggy/source_code.rb', line 110 def head @head end |
#tail ⇒ Object
Returns the value of attribute tail.
110 111 112 |
# File 'lib/yadriggy/source_code.rb', line 110 def tail @tail end |
Class Method Details
.append!(lst1, lst2) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/yadriggy/source_code.rb', line 125 def self.append!(lst1, lst2) if lst1 == nil lst2 elsif lst2 == nil lst1 else p = lst1 while p.tail != nil p = p.tail end p.tail = lst2 lst1 end end |
Instance Method Details
#each ⇒ Object
150 151 152 153 154 155 156 |
# File 'lib/yadriggy/source_code.rb', line 150 def each() list = self while list != nil yield list.head list = list.tail end end |
#fold(acc) ⇒ Object
158 159 160 161 162 163 164 165 |
# File 'lib/yadriggy/source_code.rb', line 158 def fold(acc) list = self while list != nil acc = yield acc, list.head list = list.tail end acc end |
#size ⇒ Object
140 141 142 143 144 145 146 147 148 |
# File 'lib/yadriggy/source_code.rb', line 140 def size() size = 0 list = self while list != nil list = list.tail size += 1 end size end |