module GirFFI::BuilderHelper

Set of helper methods used in the builders.

Public Instance Methods

get_or_define_class(namespace, name, parent = nil) { || ... } click to toggle source
# File lib/gir_ffi/builder_helper.rb, line 14
def get_or_define_class(namespace, name, parent = nil)
  klass = optionally_define_constant(namespace, name) do
    parent ||= yield
    Class.new parent
  end
  if parent && klass.superclass != parent
    raise "Expected #{klass} to have superclass #{parent}, found #{klass.superclass}"
  end

  klass
end
get_or_define_module(parent, name) click to toggle source
# File lib/gir_ffi/builder_helper.rb, line 26
def get_or_define_module(parent, name)
  optionally_define_constant(parent, name) { Module.new }
end
optionally_define_constant(parent, name) { || ... } click to toggle source
# File lib/gir_ffi/builder_helper.rb, line 6
def optionally_define_constant(parent, name)
  if parent.const_defined? name, false
    parent.const_get name
  else
    parent.const_set name, yield
  end
end