class Argtrace::Signature

signature of method/block

Attributes

defined_class[RW]
is_singleton_method[RW]
method_id[RW]
params[RW]
return_type[RW]

Public Class Methods

new() click to toggle source
# File lib/argtrace/signature.rb, line 7
def initialize
  @is_singleton_method = false
  @params = []
end

Public Instance Methods

get_block_param() click to toggle source
# File lib/argtrace/signature.rb, line 51
def get_block_param
  @params.find{|x| x.mode == :block}
end
inspect() click to toggle source
# File lib/argtrace/signature.rb, line 59
def inspect
  to_s
end
merge(all_params, ret) click to toggle source
# File lib/argtrace/signature.rb, line 16
def merge(all_params, ret)
  unless @params
    @params = []
  end
  # all params (including optional / keyword etc)
  for i in 0...all_params.size
    if i == @params.size
      @params << all_params[i]  # TODO: dup
    else
      same_mode = @params[i].mode == all_params[i].mode
      same_name = @params[i].name == all_params[i].name
      # allow name changing only for block call
      if same_mode && (signature_for_block? || same_name)
        if all_params[i].mode == :block
          # TODO: buggy
          # merging of block parameter type is quite tricky...
          @params[i].type.merge(
            all_params[i].type.params, nil)
        else
          @params[i].type.merge_union(all_params[i].type)
        end
      else
        raise "signature change not supported"
      end
    end
  end

  if ret
    unless @return_type
      @return_type = TypeUnion.new
    end
    @return_type.merge_union(ret)
  end
end
signature_for_block?() click to toggle source
# File lib/argtrace/signature.rb, line 12
def signature_for_block?
  @method_id == nil
end
to_s() click to toggle source
# File lib/argtrace/signature.rb, line 55
def to_s
  "Signature(#{@defined_class}::#{@method_id}(" + @params.map{|x| x.to_s}.join(",") + ") => #{@return_type.to_s})"
end