Class: RBS::Types::Union

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types:, location:) ⇒ Union

Returns a new instance of Union.



714
715
716
717
# File 'lib/rbs/types.rb', line 714

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



712
713
714
# File 'lib/rbs/types.rb', line 712

def location
  @location
end

#typesObject (readonly)

Returns the value of attribute types.



711
712
713
# File 'lib/rbs/types.rb', line 711

def types
  @types
end

Instance Method Details

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



719
720
721
# File 'lib/rbs/types.rb', line 719

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

#each_type(&block) ⇒ Object



754
755
756
757
758
759
760
# File 'lib/rbs/types.rb', line 754

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

#free_variables(set = Set.new) ⇒ Object



729
730
731
732
733
734
735
# File 'lib/rbs/types.rb', line 729

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)


781
782
783
# File 'lib/rbs/types.rb', line 781

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

#has_self_type?Boolean

Returns:

  • (Boolean)


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

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

#hashObject



725
726
727
# File 'lib/rbs/types.rb', line 725

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

#map_type(&block) ⇒ Object



762
763
764
765
766
767
768
# File 'lib/rbs/types.rb', line 762

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

#map_type_name(&block) ⇒ Object



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

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

#sub(s) ⇒ Object



741
742
743
744
# File 'lib/rbs/types.rb', line 741

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

#to_json(state = _ = nil) ⇒ Object



737
738
739
# File 'lib/rbs/types.rb', line 737

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

#to_s(level = 0) ⇒ Object



746
747
748
749
750
751
752
# File 'lib/rbs/types.rb', line 746

def to_s(level = 0)
  if level > 0
    "(#{types.join(" | ")})"
  else
    types.join(" | ")
  end
end

#with_nonreturn_void?Boolean

Returns:

  • (Boolean)


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

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