Class: FFI::ConstGenerator::Constant

### Home Classes Methods

### In Files

- lib/ffi/tools/const_generator.rb

### Parent

Object

### Methods

- ::new
- #converted_value
- #ruby_name
- #to_ruby

### Class/Module Index

Quicksearch

- FFI
- FFI::AutoPointer
- FFI::AutoPointer::CallableReleaser
- FFI::AutoPointer::DefaultReleaser
- FFI::AutoPointer::Releaser
- FFI::ConstGenerator
- FFI::ConstGenerator::Constant
- FFI::Enum
- FFI::Enums
- FFI::Generator
- FFI::Generator::Task
- FFI::IO
- FFI::ManagedStruct
- FFI::Platform
- FFI::PlatformError
- FFI::Pointer
- FFI::StrPtrConverter
- FFI::Struct
- FFI::Struct::ManagedStructConverter
- FFI::StructGenerator
- FFI::StructGenerator::Field
- FFI::StructLayout
- FFI::StructLayout::Enum
- FFI::StructLayout::InnerStruct
- FFI::StructLayout::Mapped
- FFI::StructLayoutBuilder
- FFI::TypesGenerator
- FFI::Union
- FFI::VariadicInvoker

No matching classes.

# FFI::ConstGenerator::Constant

This class hold constants for {ConstGenerator}

### Attributes

cast[R]
format[R]
name[R]
value[RW]

### Public Class Methods

new(name, format, cast, ruby_name = nil, converter=nil) click to toggle source

@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 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

### Public Instance Methods

converted_value() click to toggle source

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

    # File lib/ffi/tools/const_generator.rb, line 207
    def converted_value
      if @converter
        @converter.call(@value)
      else
        @value
      end
    end

ruby_name() click to toggle source

get constant ruby name @return [String]

    # File lib/ffi/tools/const_generator.rb, line 217
    def ruby_name
      @ruby_name || @name
    end

to_ruby() click to toggle source

Get an evaluable string from constant. @return [String]

    # File lib/ffi/tools/const_generator.rb, line 223
    def to_ruby
      "#{ruby_name} = #{converted_value}"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.