Class: Yadriggy::CompositeType

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

Overview

Parametric types.

Direct Known Subclasses

Yadriggy::C::ArrayType

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

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

Constructor Details

#initialize(name, args) ⇒ CompositeType

Returns a new instance of CompositeType.

Parameters:

  • name (Module)

    type name.

  • args (Array<Type>|Type)

    type arguments.



569
570
571
572
# File 'lib/yadriggy/type.rb', line 569

def initialize(name, args)
  @ruby_class = name
  @args = args.is_a?(Array) ? args : [ args ]
end

Instance Attribute Details

#argsArray<Type> (readonly)

Returns type arguments.

Returns:

  • (Array<Type>)

    type arguments.



565
566
567
# File 'lib/yadriggy/type.rb', line 565

def args
  @args
end

#ruby_classModule (readonly)

Returns type name. The value is a Ruby class.

Returns:

  • (Module)

    type name. The value is a Ruby class.



563
564
565
# File 'lib/yadriggy/type.rb', line 563

def ruby_class
  @ruby_class
end

Instance Method Details

#==(t) ⇒ Boolean

Checks the equality.

Parameters:

  • t (Type|Module)

    the other object.

Returns:

  • (Boolean)

    true if self and t represent the same type and their type arguments are equivalent.



583
584
585
586
587
# File 'lib/yadriggy/type.rb', line 583

def == (t)
  ct = CompositeType.role(t)
  !ct.nil? && ct.ruby_class == @ruby_class &&
    ct.args == @args
end

#first_argType

Returns the first type argument.

Returns:

  • (Type)

    the first type argument.



575
576
577
# File 'lib/yadriggy/type.rb', line 575

def first_arg
  @args[0]
end

#nameString

Obtains the name of this type.

Returns:

  • (String)

    the type name.



625
626
627
628
629
# File 'lib/yadriggy/type.rb', line 625

def name
  name = @ruby_class.name.dup
  name << '<' << @args.map{|e| e.name }.join(',') << '>'
  name
end

#supertypeRubyClass

Returns the RubyClass for this class.

Returns:



619
620
621
# File 'lib/yadriggy/type.rb', line 619

def supertype
  RubyClass[@ruby_class]
end