Class: GirFFI::Builders::MethodTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/gir_ffi/builders/method_template.rb

Overview

Encapsulates the general structure of generated methods, consisting of a preparation phase where arguments are converted to the form needed by the main call of the method, the main call itself, a post-processing phase where the return values and any ‘out’ arguments of the main call are converted into a form suitable for returning, and finally the returning of said values to the caller.

The different method builders collaborate with MethodTemplate to build the desired method.

Instance Method Summary collapse

Constructor Details

#initialize(builder, argument_builder_collection) ⇒ MethodTemplate

Returns a new instance of MethodTemplate.



15
16
17
18
# File 'lib/gir_ffi/builders/method_template.rb', line 15

def initialize(builder, argument_builder_collection)
  @builder = builder
  @argument_builder_collection = argument_builder_collection
end

Instance Method Details

#method_definitionObject



20
21
22
23
24
25
# File 'lib/gir_ffi/builders/method_template.rb', line 20

def method_definition
  code = +"def #{qualified_method_name}"
  code << "(#{method_arguments.join(", ")})" if method_arguments.any?
  method_lines.each { |line| code << "\n  #{line}" }
  code << "\nend\n"
end