Class: Nendo::Cell
Instance Attribute Summary collapse
-
#car ⇒ Object
Returns the value of attribute car.
-
#cdr ⇒ Object
Returns the value of attribute cdr.
Instance Method Summary collapse
-
#each ⇒ Object
Supporting iterator.
- #getLastAtom ⇒ Object
-
#initialize(car = Nil.new, cdr = Nil.new) ⇒ Cell
constructor
A new instance of Cell.
- #isDotted ⇒ Object
- #isNull ⇒ Object
- #lastAtom ⇒ Object
- #lastCell ⇒ Object
- #length ⇒ Object
-
#size ⇒ Object
alias of length.
- #to_arr ⇒ Object
Constructor Details
Instance Attribute Details
#car ⇒ Object
Returns the value of attribute car.
94 95 96 |
# File 'lib/nendo.rb', line 94 def car @car end |
#cdr ⇒ Object
Returns the value of attribute cdr.
94 95 96 |
# File 'lib/nendo.rb', line 94 def cdr @cdr end |
Instance Method Details
#each ⇒ Object
Supporting iterator
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/nendo.rb', line 96 def each # Supporting iterator h = {} if not isNull it = self while Nil != it.class h[ it.hash ] = true # printf( "%s : %s\n", it.car, it.hash ) yield it if it.cdr.is_a? Cell it = it.cdr if h.has_key?( it.hash ) # found circular-list. it = Nil.new end else it = Nil.new end end end end |
#getLastAtom ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/nendo.rb', line 139 def getLastAtom if self.lastAtom self.lastCell.cdr else Nendo::Nil.new end end |
#isDotted ⇒ Object
120 121 122 |
# File 'lib/nendo.rb', line 120 def isDotted ((Cell != @cdr.class) and (Nil != @cdr.class)) end |
#isNull ⇒ Object
124 125 126 |
# File 'lib/nendo.rb', line 124 def isNull ((Nil == @car.class) and (Nil == @cdr.class)) end |
#lastAtom ⇒ Object
134 135 136 137 |
# File 'lib/nendo.rb', line 134 def lastAtom lastOne = self.lastCell lastOne.isDotted end |
#lastCell ⇒ Object
128 129 130 131 132 |
# File 'lib/nendo.rb', line 128 def lastCell lastOne = self self.each { |x| lastOne = x } lastOne end |
#length ⇒ Object
117 |
# File 'lib/nendo.rb', line 117 def length() self.to_arr.length end |
#size ⇒ Object
alias of length
118 |
# File 'lib/nendo.rb', line 118 def size() self.length end |
#to_arr ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/nendo.rb', line 147 def to_arr if isNull [] else self.map {|x| x.car} end end |