Class: Yadriggy::OptionalRole

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

Overview

A role that can be attached to a Type object. It makes a chain of Type objects.

Instance Method Summary collapse

Methods inherited from Type

#!=, #eql?, error_found!, get_instance_method_object, #name, role

Constructor Details

#initialize(type) ⇒ OptionalRole

Returns a new instance of OptionalRole.

Parameters:

  • type (Type)

    a Type object that this role is added to.



635
636
637
# File 'lib/yadriggy/type.rb', line 635

def initialize(type)
  @type = type
end

Instance Method Details

#<=(t) ⇒ Object



672
673
674
# File 'lib/yadriggy/type.rb', line 672

def <= (t)
  @type <= t
end

#==(t) ⇒ Object

Checks the equality. The roles (a Yadriggy::OptionalRole objects) in the chain are ignored when objects are compared.



662
663
664
# File 'lib/yadriggy/type.rb', line 662

def == (t)
  @type == t
end

#copy(without_role) ⇒ Object



640
641
642
643
644
645
646
647
648
649
650
651
652
653
# File 'lib/yadriggy/type.rb', line 640

def copy(without_role)
  chain = @type.copy(without_role)
  if self.is_a?(without_role)
    chain
  else
    if @type.equal?(chain)
      self
    else
      new_self = self.clone()
      new_self.update_type = chain
      new_self
    end
  end
end

#exact_typeObject



691
692
693
# File 'lib/yadriggy/type.rb', line 691

def exact_type
  @type.exact_type
end

#get_method_object(method_name) ⇒ Object



696
697
698
# File 'lib/yadriggy/type.rb', line 696

def get_method_object(method_name)
  Type.get_instance_method_object(@type, method_name)
end

#has_role?(a_role) ⇒ Boolean

Returns:

  • (Boolean)


682
683
684
685
686
687
688
# File 'lib/yadriggy/type.rb', line 682

def has_role?(a_role)
  if self.is_a?(a_role)
    self
  else
    @type.has_role?(a_role)
  end
end

#hashObject



667
668
669
# File 'lib/yadriggy/type.rb', line 667

def hash
  @type.hash
end

#is_super_of?(t) ⇒ Boolean

Returns:

  • (Boolean)


677
678
679
# File 'lib/yadriggy/type.rb', line 677

def is_super_of?(t)
  @type.is_super_of?(t)
end

#supertypeType

Returns the super type.

Returns:

  • (Type)

    the super type.



701
702
703
# File 'lib/yadriggy/type.rb', line 701

def supertype
  @type.supertype
end

#update_type(t) ⇒ Object



656
657
658
# File 'lib/yadriggy/type.rb', line 656

def update_type(t)
  @type = t
end