Class: Rbind::GeneratorRuby::RTypeHelper::OverloadedOperationHelper

Inherits:
HelperBase
  • Object
show all
Defined in:
lib/rbind/generator_ruby.rb

Instance Attribute Summary

Attributes inherited from HelperBase

#name

Instance Method Summary collapse

Methods inherited from HelperBase

#full_name

Constructor Details

#initialize(root) ⇒ OverloadedOperationHelper

Returns a new instance of OverloadedOperationHelper.



457
458
459
460
461
# File 'lib/rbind/generator_ruby.rb', line 457

def initialize(root)
    raise "expect an array of methods but got #{root}" if root.size < 1
    super(GeneratorRuby.normalize_method_name(root.first.alias || root.first.name),root)
    @overload_wrapper = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","ruby","roverloaded_method_call.rb")).read,nil,"-")
end

Instance Method Details

#add_aliasObject



476
477
478
479
480
481
482
483
484
485
# File 'lib/rbind/generator_ruby.rb', line 476

def add_alias
    name = GeneratorRuby::normalize_alias_method_name(@root.first.alias || @root.first.name)
    if name == self.name || !@root.first.cplusplus_alias?
        nil
    elsif static?
        "    class << self; alias :#{name} :#{self.name}; end\n"
    else
        "    alias #{name} #{self.name}\n"
    end
end

#add_docObject



487
488
489
490
491
492
493
494
495
496
# File 'lib/rbind/generator_ruby.rb', line 487

def add_doc
    str = @root.map do |op|
        s = op.add_doc
        s ||= ""
        s = s.gsub(/( *#)/) do
            "#{$1}  "
        end
        "    # @overload #{op.name}(#{op.wrap_parameters_signature})\n#{s}"
    end.join("    #\n")
end

#add_methodsObject



463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/rbind/generator_ruby.rb', line 463

def add_methods
    str = @root.map do |method|
        next if method.ignore?
        raise "Cannot overload attributes" if method.attribute?
        op = if method.is_a? OperationHelper
                 method
             else
                 OperationHelper.new(method)
             end
        @overload_wrapper.result(op.binding)
    end.join("\n")
end

#bindingObject



498
499
500
# File 'lib/rbind/generator_ruby.rb', line 498

def binding
    Kernel.binding
end