Class: FFI::ConstGenerator::Constant
- Inherits:
-
Object
- Object
- FFI::ConstGenerator::Constant
- Defined in:
- lib/ffi/tools/const_generator.rb
Overview
This class hold constants for FFI::ConstGenerator
Instance Attribute Summary (collapse)
-
- (Object) cast
readonly
Returns the value of attribute cast.
-
- (Object) format
readonly
Returns the value of attribute format.
-
- (Object) name
readonly
Returns the value of attribute name.
-
- (Object) value
Returns the value of attribute value.
Instance Method Summary (collapse)
-
- (Object) converted_value
Return constant value (converted if a converter was defined).
-
- (Constant) initialize(name, format, cast, ruby_name = nil, converter = nil)
constructor
A new instance of Constant.
-
- (String) ruby_name
get constant ruby name.
-
- (String) to_ruby
Get an evaluable string from constant.
Constructor Details
- (Constant) initialize(name, format, cast, ruby_name = nil, converter = nil)
A new instance of Constant
196 197 198 199 200 201 202 203 |
# File 'lib/ffi/tools/const_generator.rb', line 196 def initialize(name, format, cast, ruby_name = nil, converter=nil) @name = name @format = format @cast = cast @ruby_name = ruby_name @converter = converter @value = nil end |
Instance Attribute Details
- (Object) cast (readonly)
Returns the value of attribute cast
187 188 189 |
# File 'lib/ffi/tools/const_generator.rb', line 187 def cast @cast end |
- (Object) format (readonly)
Returns the value of attribute format
187 188 189 |
# File 'lib/ffi/tools/const_generator.rb', line 187 def format @format end |
- (Object) name (readonly)
Returns the value of attribute name
187 188 189 |
# File 'lib/ffi/tools/const_generator.rb', line 187 def name @name end |
- (Object) value
Returns the value of attribute value
188 189 190 |
# File 'lib/ffi/tools/const_generator.rb', line 188 def value @value end |
Instance Method Details
- (Object) converted_value
Return constant value (converted if a converter was defined).
207 208 209 210 211 212 213 |
# File 'lib/ffi/tools/const_generator.rb', line 207 def converted_value if @converter @converter.call(@value) else @value end end |
- (String) ruby_name
get constant ruby name
217 218 219 |
# File 'lib/ffi/tools/const_generator.rb', line 217 def ruby_name @ruby_name || @name end |
- (String) to_ruby
Get an evaluable string from constant.
223 224 225 |
# File 'lib/ffi/tools/const_generator.rb', line 223 def to_ruby "#{ruby_name} = #{converted_value}" end |