Module: CZTop::HasFFIDelegate::ClassMethods

Includes:
Forwardable
Included in:
Actor, CertStore, Certificate, Config, Frame, Message, Poller::ZPoller, Socket, Z85
Defined in:
lib/cztop/has_ffi_delegate.rb

Overview

Some class methods related to FFI delegates.

Instance Method Summary collapse

Instance Method Details

#ffi_delegate(method) ⇒ void

Note:

It only takes one method name so it's easy to add some documentation for each delegated method.

This method returns an undefined value.

Delegate specified instance method to the registered FFI delegate.

Parameters:

  • method (Symbol)

    method to delegate


72
73
74
# File 'lib/cztop/has_ffi_delegate.rb', line 72

def ffi_delegate(method)
  def_delegator(:@ffi_delegate, method)
end

#from_ffi_delegate(ffi_delegate) ⇒ CZTop::*

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).

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.

Returns:


84
85
86
87
88
# 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