Class: FFIDB::Enum

Inherits:
Object
  • Object
show all
Includes:
Symbolic
Defined in:
lib/ffidb/enum.rb

Instance Method Summary collapse

Methods included from Symbolic

#<=>, #function?, #kind, #kind_weight, #struct?, #to_yaml, #typedef?, #union?

Constructor Details

#initialize(name, values = {}, comment = nil) ⇒ Enum

Returns a new instance of Enum.

Parameters:

  • name (Symbol, #to_sym)
  • values (Map<String, Integer>) (defaults to: {})
  • comment (String, #to_s) (defaults to: nil)


13
14
15
# File 'lib/ffidb/enum.rb', line 13

def initialize(name, values = {}, comment = nil)
  super(name.to_sym, values || {}, comment&.to_s)
end

Instance Method Details

#enum?Boolean

Returns:

  • (Boolean)


19
# File 'lib/ffidb/enum.rb', line 19

def enum?() return true end

#to_hHash<Symbol, Type>

Returns:

  • (Hash<Symbol, Type>)


29
30
31
32
33
34
35
# File 'lib/ffidb/enum.rb', line 29

def to_h
  {
    name: self.name.to_s,
    comment: self.comment,
    values: self.values,
  }.delete_if { |k, v| v.nil? }
end

#to_sString

Returns:

  • (String)


23
24
25
# File 'lib/ffidb/enum.rb', line 23

def to_s
  "enum #{self.name}"
end