module CZTop::HasFFIDelegate::ClassMethods

Some class methods related to FFI delegates.

Public Instance Methods

ffi_delegate(method) click to toggle source

Delegate specified instance method to the registered FFI delegate. @note It only takes one method name so it's easy to add some

documentation for each delegated method.

@param method [Symbol] method to delegate @return [void]

# File lib/cztop/has_ffi_delegate.rb, line 72
def ffi_delegate(method)
  def_delegator(:@ffi_delegate, method)
end
from_ffi_delegate(ffi_delegate) click to toggle source

Allocates a new instance and attaches the FFI delegate to it. This is useful if you already have an FFI delegate and need to attach it to a fresh high-level object. @return [CZTop::*] the fresh object @note initialize won't be called on the fresh object. This works around

the fact that #initialize usually assumes that no FFI delegate is
attached yet and will try to do so (and also expect to be called in a
specific way).
# File lib/cztop/has_ffi_delegate.rb, line 84
def from_ffi_delegate(ffi_delegate)
  obj = allocate
  obj.attach_ffi_delegate(ffi_delegate)
  return obj
end