Class FFI::Enum
In: lib/ffi/enum.rb
Parent: Object

Represents a C enum.

For a C enum:

 enum fruits {
   apple,
   banana,
   orange,
   pineapple
 };

are defined this vocabulary:

  • a symbol is a word from the enumeration (ie. apple, by example);
  • a value is the value of a symbol in the enumeration (by example, apple has value _0_ and banana _1_).

Methods

[]   find   from_native   new   symbol_map   symbols   to_h   to_hash   to_native  

Included Modules

DataConverter

Attributes

native_type  [R] 
tag  [R] 

Public Class methods

@overload initialize(info, tag=nil)

  @param [nil, Enumerable] info
  @param [nil, Symbol] tag enum tag

@overload initialize(native_type, info, tag=nil)

  @param [FFI::Type] native_type Native type for new Enum
  @param [nil, Enumerable] info symbols and values for new Enum
  @param [nil, Symbol] tag name of new Enum

Public Instance methods

Get a symbol or a value from the enum. @overload [](query)

 Get enum value from symbol.
 @param [Symbol] query
 @return [Integer]

@overload [](query)

 Get enum symbol from value.
 @param [Integer] query
 @return [Symbol]
find(query)

Alias for #[]

@param val @return symbol name if it exists for val.

Get the symbol map. @return [Hash]

@return [Array] enum symbol names

to_h()

Alias for symbol_map

to_hash()

Alias for symbol_map

@param [Symbol, Integer, to_int] val @param ctx unused @return [Integer] value of a enum symbol

[Validate]