Class: FFI::ConstGenerator::Constant

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/tools/const_generator.rb

Overview

This class hold constants for FFI::ConstGenerator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, format, cast, ruby_name = nil, converter = nil) ⇒ Constant

Returns a new instance of Constant.

Parameters:

  • name (#to_s)
  • format (String)

    a printf format string to print the value out

  • cast (String)

    a C cast for the value

  • ruby_name (defaults to: nil)

    alternate ruby name for #to_ruby

  • converter (#call) (defaults to: nil)

    convert the value from a string to the appropriate type for #to_ruby.



199
200
201
202
203
204
205
206
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/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

Instance Attribute Details

#castObject (readonly)

Returns the value of attribute cast.



190
191
192
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/tools/const_generator.rb', line 190

def cast
  @cast
end

#formatObject (readonly)

Returns the value of attribute format.



190
191
192
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/tools/const_generator.rb', line 190

def format
  @format
end

#nameObject (readonly)

Returns the value of attribute name.



190
191
192
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/tools/const_generator.rb', line 190

def name
  @name
end

#valueObject

Returns the value of attribute value.



191
192
193
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/tools/const_generator.rb', line 191

def value
  @value
end

Instance Method Details

#converted_valueObject

Return constant value (converted if a converter was defined).

Returns:

  • constant value.



210
211
212
213
214
215
216
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/tools/const_generator.rb', line 210

def converted_value
  if @converter
    @converter.call(@value)
  else
    @value
  end
end

#ruby_nameString

get constant ruby name

Returns:



220
221
222
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/tools/const_generator.rb', line 220

def ruby_name
  @ruby_name || @name
end

#to_rubyString

Get an evaluable string from constant.

Returns:



226
227
228
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/tools/const_generator.rb', line 226

def to_ruby
  "#{ruby_name} = #{converted_value}"
end