Module: GirFFI::BuilderHelper

Included in:
BaseTypeBuilder, Builder, GirFFI::Builders::ModuleBuilder
Defined in:
lib/gir_ffi/builder_helper.rb

Overview

Set of helper methods used in the builders.

Instance Method Summary collapse

Instance Method Details

#get_or_define_class(namespace, name, parent) ⇒ Object



13
14
15
# File 'lib/gir_ffi/builder_helper.rb', line 13

def get_or_define_class(namespace, name, parent)
  optionally_define_constant(namespace, name) { Class.new parent }
end

#get_or_define_module(parent, name) ⇒ Object



17
18
19
# File 'lib/gir_ffi/builder_helper.rb', line 17

def get_or_define_module(parent, name)
  optionally_define_constant(parent, name) { Module.new }
end

#optionally_define_constant(parent, name) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/gir_ffi/builder_helper.rb', line 5

def optionally_define_constant(parent, name)
  if parent.const_defined? name, false
    parent.const_get name
  else
    parent.const_set name, yield
  end
end