Class: Elparser::SExpList
- Inherits:
-
AbstractSExpCons
- Object
- AbstractSExp
- AbstractSExpCons
- Elparser::SExpList
- Defined in:
- lib/elparser.rb
Instance Attribute Summary collapse
-
#list ⇒ Object
readonly
Returns the value of attribute list.
Instance Method Summary collapse
- #alist? ⇒ Boolean
- #car ⇒ Object
- #cdr ⇒ Object
-
#initialize(list) ⇒ SExpList
constructor
A new instance of SExpList.
- #list? ⇒ Boolean
-
#to_h ⇒ Object
alist -> hash.
- #to_ruby ⇒ Object
- #to_s ⇒ Object
- #visit(&block) ⇒ Object
Methods inherited from AbstractSExpCons
Methods inherited from AbstractSExp
Constructor Details
#initialize(list) ⇒ SExpList
Returns a new instance of SExpList.
143 144 145 |
# File 'lib/elparser.rb', line 143 def initialize(list) @list = list end |
Instance Attribute Details
#list ⇒ Object (readonly)
Returns the value of attribute list.
142 143 144 |
# File 'lib/elparser.rb', line 142 def list @list end |
Instance Method Details
#alist? ⇒ Boolean
168 169 170 |
# File 'lib/elparser.rb', line 168 def alist? @list.all? {|i| i.cons? } end |
#car ⇒ Object
146 147 148 |
# File 'lib/elparser.rb', line 146 def car @list[0] end |
#cdr ⇒ Object
149 150 151 152 153 154 155 |
# File 'lib/elparser.rb', line 149 def cdr if @list.size == 1 SExpNil.new else SExpList.new @list.slice(1..-1) end end |
#list? ⇒ Boolean
156 157 158 |
# File 'lib/elparser.rb', line 156 def list? true end |
#to_h ⇒ Object
alist -> hash
172 173 174 175 176 177 178 |
# File 'lib/elparser.rb', line 172 def to_h ret = Hash.new @list.each do |i| ret[i.car.to_ruby] = i.cdr.to_ruby end ret end |
#to_ruby ⇒ Object
165 166 167 |
# File 'lib/elparser.rb', line 165 def to_ruby @list.map {|i| i.to_ruby} end |
#to_s ⇒ Object
159 160 161 |
# File 'lib/elparser.rb', line 159 def to_s "("+@list.map{|i| i.to_s }.join(" ")+")" end |
#visit(&block) ⇒ Object
162 163 164 |
# File 'lib/elparser.rb', line 162 def visit(&block) @list = @list.map(&block) end |