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.



801
802
803
804
# File 'lib/rbs/types.rb', line 801

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

#typesObject (readonly)

Returns the value of attribute types.



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

def types
  @types
end

Instance Method Details

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



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

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

#each_type(&block) ⇒ Object



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

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

#free_variables(set = Set.new) ⇒ Object



816
817
818
819
820
821
822
# File 'lib/rbs/types.rb', line 816

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)


869
870
871
# File 'lib/rbs/types.rb', line 869

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

#has_self_type?Boolean

Returns:

  • (Boolean)


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

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

#hashObject



812
813
814
# File 'lib/rbs/types.rb', line 812

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

#map_type(&block) ⇒ Object



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

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



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

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

#sub(s) ⇒ Object



828
829
830
831
# File 'lib/rbs/types.rb', line 828

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

#to_json(state = _ = nil) ⇒ Object



824
825
826
# File 'lib/rbs/types.rb', line 824

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

#to_s(level = 0) ⇒ Object



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

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)


873
874
875
# File 'lib/rbs/types.rb', line 873

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