Class: RBS::Types::Intersection

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types:, location:) ⇒ Intersection

Returns a new instance of Intersection.



794
795
796
797
# File 'lib/rbs/types.rb', line 794

def initialize(types:, location:)
  @types = types
  @location = location
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



792
793
794
# File 'lib/rbs/types.rb', line 792

def location
  @location
end

#typesObject (readonly)

Returns the value of attribute types.



791
792
793
# File 'lib/rbs/types.rb', line 791

def types
  @types
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



799
800
801
# File 'lib/rbs/types.rb', line 799

def ==(other)
  other.is_a?(Intersection) && other.types == types
end

#each_type(&block) ⇒ Object



835
836
837
838
839
840
841
# File 'lib/rbs/types.rb', line 835

def each_type(&block)
  if block
    types.each(&block)
  else
    enum_for :each_type
  end
end

#free_variables(set = Set.new) ⇒ Object



809
810
811
812
813
814
815
# File 'lib/rbs/types.rb', line 809

def free_variables(set = Set.new)
  set.tap do
    types.each do |type|
      type.free_variables set
    end
  end
end

#has_classish_type?Boolean

Returns:

  • (Boolean)


862
863
864
# File 'lib/rbs/types.rb', line 862

def has_classish_type?
  each_type.any? {|type| type.has_classish_type? }
end

#has_self_type?Boolean

Returns:

  • (Boolean)


858
859
860
# File 'lib/rbs/types.rb', line 858

def has_self_type?
  each_type.any? {|type| type.has_self_type? }
end

#hashObject



805
806
807
# File 'lib/rbs/types.rb', line 805

def hash
  self.class.hash ^ types.hash
end

#map_type(&block) ⇒ Object



843
844
845
846
847
848
849
# File 'lib/rbs/types.rb', line 843

def map_type(&block)
  if block
    Intersection.new(types: types.map(&block), location: location)
  else
    enum_for :map_type
  end
end

#map_type_name(&block) ⇒ Object



851
852
853
854
855
856
# File 'lib/rbs/types.rb', line 851

def map_type_name(&block)
  Intersection.new(
    types: types.map {|type| type.map_type_name(&block) },
    location: location
  )
end

#sub(s) ⇒ Object



821
822
823
824
# File 'lib/rbs/types.rb', line 821

def sub(s)
  self.class.new(types: types.map {|ty| ty.sub(s) },
                 location: location)
end

#to_json(state = _ = nil) ⇒ Object



817
818
819
# File 'lib/rbs/types.rb', line 817

def to_json(state = _ = nil)
  { class: :intersection, types: types, location: location }.to_json(state)
end

#to_s(level = 0) ⇒ Object



826
827
828
829
830
831
832
833
# File 'lib/rbs/types.rb', line 826

def to_s(level = 0)
  strs = types.map {|ty| ty.to_s(2) }
  if level > 0
    "(#{strs.join(" & ")})"
  else
    strs.join(" & ")
  end
end

#with_nonreturn_void?Boolean

Returns:

  • (Boolean)


866
867
868
# File 'lib/rbs/types.rb', line 866

def with_nonreturn_void?
  each_type.any? {|type| type.with_nonreturn_void? }
end