Class: GirFFI::Builders::ConstructorBuilder
- Inherits:
-
Object
- Object
- GirFFI::Builders::ConstructorBuilder
- Defined in:
- lib/gir_ffi/builders/constructor_builder.rb
Overview
Implements the creation of a Ruby constructor definition out of a GIR IFunctionInfo. TODO: Derive from BaseMethodBuilder
Instance Method Summary collapse
-
#initialize(info) ⇒ ConstructorBuilder
constructor
A new instance of ConstructorBuilder.
- #invocation ⇒ Object
- #method_arguments ⇒ Object
- #method_definition ⇒ Object
- #method_name ⇒ Object
- #preparation ⇒ Object
- #result ⇒ Object
- #singleton_method? ⇒ Boolean
Constructor Details
#initialize(info) ⇒ ConstructorBuilder
Returns a new instance of ConstructorBuilder.
13 14 15 16 17 18 |
# File 'lib/gir_ffi/builders/constructor_builder.rb', line 13 def initialize(info) @info = info return_value_builder = NullReturnValueBuilder.new arg_builders = ArgumentBuilderCollection.new(return_value_builder, []) @template = MethodTemplate.new(self, arg_builders) end |
Instance Method Details
#invocation ⇒ Object
47 48 49 |
# File 'lib/gir_ffi/builders/constructor_builder.rb', line 47 def invocation "obj.__send__ #{initializer_name.to_sym.inspect}, #{method_arguments.join(", ")}" end |
#method_arguments ⇒ Object
32 33 34 |
# File 'lib/gir_ffi/builders/constructor_builder.rb', line 32 def method_arguments ["*args", "&block"] end |
#method_definition ⇒ Object
20 21 22 |
# File 'lib/gir_ffi/builders/constructor_builder.rb', line 20 def method_definition @template.method_definition end |
#method_name ⇒ Object
28 29 30 |
# File 'lib/gir_ffi/builders/constructor_builder.rb', line 28 def method_name @info.safe_name end |
#preparation ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gir_ffi/builders/constructor_builder.rb', line 36 def preparation if @info.safe_name == "new" ["obj = allocate"] else [ "raise NoMethodError unless self == #{@info.container.full_name}", "obj = allocate" ] end end |
#result ⇒ Object
51 52 53 |
# File 'lib/gir_ffi/builders/constructor_builder.rb', line 51 def result ["obj"] end |
#singleton_method? ⇒ Boolean
24 25 26 |
# File 'lib/gir_ffi/builders/constructor_builder.rb', line 24 def singleton_method? true end |