Class: CType::Enum
- Inherits:
-
Object
- Object
- CType::Enum
- Defined in:
- lib/dbc/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.
215 216 217 218 |
# File 'lib/dbc/ctype.rb', line 215 def initialize(name) @name = name @members = nil end |
Class Method Details
Instance Method Details
#add(items) ⇒ Object
219 220 221 222 223 |
# File 'lib/dbc/ctype.rb', line 219 def add(items) warn "enum #{@name} already defined" if @members @members = items self end |
#evaluate ⇒ Object
224 225 226 227 |
# File 'lib/dbc/ctype.rb', line 224 def evaluate CType.evaluation_error(identifier) unless identifier.empty? self end |
#to_def(indent = '') ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/dbc/ctype.rb', line 237 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
231 232 233 234 235 236 |
# File 'lib/dbc/ctype.rb', line 231 def to_init_s(ident=nil) str = 'enum' str << ' ' << @name if @name str << ' ' << ident if ident str end |
#to_s ⇒ Object
228 229 230 |
# File 'lib/dbc/ctype.rb', line 228 def to_s to_init_s() end |