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

Attributes included from Logger

#log

Instance Method Summary collapse

Methods inherited from HelperBase

#full_name

Methods included from Logger

extend_object

Constructor Details

#initialize(root) ⇒ OverloadedOperationHelper

Returns a new instance of OverloadedOperationHelper.



552
553
554
555
556
# File 'lib/rbind/generator_ruby.rb', line 552

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



571
572
573
574
575
576
577
578
579
580
# File 'lib/rbind/generator_ruby.rb', line 571

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



582
583
584
585
586
587
588
589
590
591
# File 'lib/rbind/generator_ruby.rb', line 582

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



558
559
560
561
562
563
564
565
566
567
568
569
# File 'lib/rbind/generator_ruby.rb', line 558

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



593
594
595
# File 'lib/rbind/generator_ruby.rb', line 593

def binding
    Kernel.binding
end