class FFI::ConstGenerator::Constant
This class hold constants for {ConstGenerator}
Attributes
Public Class Methods
@param [#to_s] name @param [String] format a printf format string to print the value out @param [String] cast a C cast for the value @param ruby_name
alternate ruby name for {#to_ruby} @param [#call] converter convert the value from a string to the appropriate
type for {#to_ruby}.
# File lib/ffi/tools/const_generator.rb, line 199 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
Public Instance Methods
Return constant value (converted if a converter
was defined). @return constant value.
# File lib/ffi/tools/const_generator.rb, line 210 def converted_value if @converter @converter.call(@value) else @value end end
get constant ruby name @return [String]
# File lib/ffi/tools/const_generator.rb, line 220 def ruby_name @ruby_name || @name end
Get an evaluable string from constant. @return [String]
# File lib/ffi/tools/const_generator.rb, line 226 def to_ruby "#{ruby_name} = #{converted_value}" end