Class: Yadriggy::CompositeType
Overview
Parametric types.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#args ⇒ Array<Type>
readonly
Type arguments.
-
#ruby_class ⇒ Module
readonly
Type name.
Instance Method Summary collapse
-
#==(t) ⇒ Boolean
Checks the equality.
-
#first_arg ⇒ Type
The first type argument.
-
#initialize(name, args) ⇒ CompositeType
constructor
A new instance of CompositeType.
-
#name ⇒ String
Obtains the name of this type.
-
#supertype ⇒ RubyClass
The RubyClass for this class.
Methods inherited from Type
#!=, #copy, #eql?, error_found!, #has_role?, role
Constructor Details
#initialize(name, args) ⇒ CompositeType
Returns a new instance of CompositeType.
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
#args ⇒ Array<Type> (readonly)
Returns type arguments.
565 566 567 |
# File 'lib/yadriggy/type.rb', line 565 def args @args end |
#ruby_class ⇒ Module (readonly)
Returns 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.
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_arg ⇒ Type
Returns the first type argument.
575 576 577 |
# File 'lib/yadriggy/type.rb', line 575 def first_arg @args[0] end |
#name ⇒ String
Obtains the name of this type.
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 |