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.



773
774
775
776
# File 'lib/rbs/types.rb', line 773

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



771
772
773
# File 'lib/rbs/types.rb', line 771

def location
  @location
end

#typesObject (readonly)

Returns the value of attribute types.



770
771
772
# File 'lib/rbs/types.rb', line 770

def types
  @types
end

Instance Method Details

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



778
779
780
# File 'lib/rbs/types.rb', line 778

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

#each_type(&block) ⇒ Object



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

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

#free_variables(set = Set.new) ⇒ Object



788
789
790
791
792
793
794
# File 'lib/rbs/types.rb', line 788

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)


841
842
843
# File 'lib/rbs/types.rb', line 841

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

#has_self_type?Boolean

Returns:

  • (Boolean)


837
838
839
# File 'lib/rbs/types.rb', line 837

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

#hashObject



784
785
786
# File 'lib/rbs/types.rb', line 784

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

#map_type(&block) ⇒ Object



822
823
824
825
826
827
828
# File 'lib/rbs/types.rb', line 822

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



830
831
832
833
834
835
# File 'lib/rbs/types.rb', line 830

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

#sub(s) ⇒ Object



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

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

#to_json(state = _ = nil) ⇒ Object



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

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

#to_s(level = 0) ⇒ Object



805
806
807
808
809
810
811
812
# File 'lib/rbs/types.rb', line 805

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)


845
846
847
# File 'lib/rbs/types.rb', line 845

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