Class: Yadriggy::MethodType

Inherits:
Type
  • Object
show all
Defined in:
lib/yadriggy/type.rb

Overview

Type of methods.

Instance Method Summary collapse

Methods inherited from Type

#!=, #copy, #eql?, error_found!, #exact_type, #has_role?, role, #supertype

Constructor Details

#initialize(method_def = nil, param_type_array, result_type) ⇒ MethodType

Returns a new instance of MethodType.

Parameters:

  • method_def (Parameters|nil) (defaults to: nil)

    method definition.

  • param_type_array (Array<Type|Module>|DynType)

    parameter types. param_type_array can be DynType.

  • result_type (Type|Module|DynType)

    the result type.



477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'lib/yadriggy/type.rb', line 477

def initialize(method_def=nil, param_type_array, result_type)
  @param_types = if param_type_array.is_a?(Array)
                   param_type_array.map do |t|
                     t.is_a?(Type) ? t : RubyClass[t]
                   end
                 else
                   param_type_array
                 end
  @result_type = if result_type.is_a?(Type)
                   result_type
                 else
                   RubyClass[result_type]
                 end
  @method_def = method_def
end

Instance Method Details

#method_defParameters

Returns the method definition.

Returns:



501
# File 'lib/yadriggy/type.rb', line 501

def method_def() @method_def end

#nameString

Obtains the name of this type.

Returns:

  • (String)

    the type name.



533
534
535
536
537
538
539
540
541
542
# File 'lib/yadriggy/type.rb', line 533

def name
  name = ''
  if @param_types.is_a?(Array)
    name << '(' << @param_types.map{|e| e.name }.join(',') << ')'
  else
    name << @param_types.name
  end
  name  << '->' << @result_type.name
  name
end

#paramsArray<Type>|DynType

Gets an array of the parameter types.

Returns:



495
# File 'lib/yadriggy/type.rb', line 495

def params() @param_types end

#resultResultType

Returns the result type. Note that a ResultType object is always returned.

Returns:



527
528
529
# File 'lib/yadriggy/type.rb', line 527

def result()
  ResultType.new(@result_type, @method_def)
end

#result_typeType

Returns the result type.

Returns:

  • (Type)

    the result type.



498
# File 'lib/yadriggy/type.rb', line 498

def result_type() @result_type end