Class: 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.
-
#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
#initialize(car = Nil.new, cdr = Nil.new) ⇒ Cell
Returns a new instance of Cell.
49 50 51 52 |
# File 'lib/nendo.rb', line 49 def initialize( car = Nil.new, cdr = Nil.new ) @car = car @cdr = cdr end |
Instance Attribute Details
#car ⇒ Object
Returns the value of attribute car.
53 54 55 |
# File 'lib/nendo.rb', line 53 def car @car end |
#cdr ⇒ Object
Returns the value of attribute cdr.
53 54 55 |
# File 'lib/nendo.rb', line 53 def cdr @cdr end |
Instance Method Details
#each ⇒ Object
Supporting iterator
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/nendo.rb', line 55 def each # Supporting iterator if not isNull it = self while Nil != it.class yield it if it.cdr.is_a? Cell it = it.cdr else it = Nil.new end end end end |
#isDotted ⇒ Object
72 73 74 |
# File 'lib/nendo.rb', line 72 def isDotted ((Cell != @cdr.class) and (Nil != @cdr.class)) end |
#isNull ⇒ Object
76 77 78 |
# File 'lib/nendo.rb', line 76 def isNull ((Nil == @car.class) and (Nil == @cdr.class)) end |
#lastAtom ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/nendo.rb', line 86 def lastAtom lastOne = self.lastCell if lastOne.isDotted lastOne.cdr else nil end end |
#lastCell ⇒ Object
80 81 82 83 84 |
# File 'lib/nendo.rb', line 80 def lastCell lastOne = self self.each { |x| lastOne = x } lastOne end |
#length ⇒ Object
69 |
# File 'lib/nendo.rb', line 69 def length() self.to_arr.length end |
#size ⇒ Object
alias of length
70 |
# File 'lib/nendo.rb', line 70 def size() self.length end |
#to_arr ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/nendo.rb', line 95 def to_arr if isNull [] else self.map {|x| x.car} end end |