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.



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

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:



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

def method_def() @method_def end

#nameString

Obtains the name of this type.

Returns:

  • (String)

    the type name.



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

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:



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

def params() @param_types end

#resultResultType

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

Returns:



529
530
531
# File 'lib/yadriggy/type.rb', line 529

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

#result_typeType

Returns the result type.

Returns:

  • (Type)

    the result type.



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

def result_type() @result_type end