Class: CType::Enum
- Inherits:
-
Object
- Object
- CType::Enum
- Defined in:
- lib/caphir/ctype.rb
Overview
Union
Constant Summary collapse
- @@enums =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #add(items) ⇒ Object
- #evaluate ⇒ Object
-
#initialize(name) ⇒ Enum
constructor
A new instance of Enum.
- #to_def(indent = '') ⇒ Object
- #to_init_s(ident = nil) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ Enum
Returns a new instance of Enum.
201 202 203 204 |
# File 'lib/caphir/ctype.rb', line 201 def initialize(name) @name = name @members = nil end |
Class Method Details
Instance Method Details
#add(items) ⇒ Object
205 206 207 208 209 |
# File 'lib/caphir/ctype.rb', line 205 def add(items) warn "enum #{@name} already defined" if @members @members = items self end |
#evaluate ⇒ Object
210 211 212 213 |
# File 'lib/caphir/ctype.rb', line 210 def evaluate CType.evaluation_error(identifier) unless identifier.empty? self end |
#to_def(indent = '') ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/caphir/ctype.rb', line 223 def to_def(indent='') str = to_s str << " {\n" @members.each do |name, num| str << indent << "\t" << name str << " = #{num.to_s}" if num str << ",\n" end str[-2, 2] = "\n" # get rid of trailing comma str << indent << "}" end |
#to_init_s(ident = nil) ⇒ Object
217 218 219 220 221 222 |
# File 'lib/caphir/ctype.rb', line 217 def to_init_s(ident=nil) str = 'enum' str << ' ' << @name if @name str << ' ' << ident if ident str end |
#to_s ⇒ Object
214 215 216 |
# File 'lib/caphir/ctype.rb', line 214 def to_s to_init_s() end |