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
- #get_or_define_class(namespace, name, parent = nil) ⇒ Object
- #get_or_define_module(parent, name) ⇒ Object
- #optionally_define_constant(parent, name) ⇒ Object
Instance Method Details
#get_or_define_class(namespace, name, parent = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# 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) ⇒ Object
26 27 28 |
# 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) ⇒ Object
6 7 8 9 10 11 12 |
# 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 |