Sha256: b4cb848b4c31999c1930c8dec65a183e8adcac8095fd22fe845ac191d51edfb2

Contents?: true

Size: 527 Bytes

Versions: 6

Compression:

Stored size: 527 Bytes

Contents

module GirFFI
  # Set of helper methods used in the builders.
  module BuilderHelper
    def optionally_define_constant parent, name
      if parent.const_defined? name, false
        parent.const_get name
      else
        parent.const_set name, yield
      end
    end

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gir_ffi-0.7.10 lib/gir_ffi/builder_helper.rb
gir_ffi-0.7.9 lib/gir_ffi/builder_helper.rb
gir_ffi-0.7.8 lib/gir_ffi/builder_helper.rb
gir_ffi-0.7.7 lib/gir_ffi/builder_helper.rb
gir_ffi-0.7.6 lib/gir_ffi/builder_helper.rb
gir_ffi-0.7.5 lib/gir_ffi/builder_helper.rb