Class: FFI::PrettyStruct

Inherits:
Struct
  • Object
show all
Defined in:
lib/ffi/prettystruct.rb

Overview

This class is obtained from ffi-tk (github.com/Tass/ffi-tk).

Constant Summary collapse

ACCESSOR_CODE =
<<-CODE
    def {name}; self[{sym}]; end
    def {name}=(value) self[{sym}] = value; end
CODE

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.layout(*kvs) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/ffi/prettystruct.rb', line 13

def self.layout(*kvs)
    kvs.each_slice(2) do |key, value|
        eval ACCESSOR_CODE.gsub(/\{(.*?)\}/, '{name}' => key, '{sym}' => ":#{key}")
    end

    super
end

Instance Method Details

#inspectObject



25
26
27
28
29
# File 'lib/ffi/prettystruct.rb', line 25

def inspect
    kvs = members.zip(values)
    kvs.map!{|key, value| "%s=%s" % [key, value.inspect] }
    "<%s %s>" % [self.class, kvs.join(' ')]
end

#membersObject



21
22
23
# File 'lib/ffi/prettystruct.rb', line 21

def members
    layout.members
end