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.



693
694
695
696
# File 'lib/rbs/types.rb', line 693

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

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



691
692
693
# File 'lib/rbs/types.rb', line 691

def location
  @location
end

#typesObject (readonly)

Returns the value of attribute types.



690
691
692
# File 'lib/rbs/types.rb', line 690

def types
  @types
end

Instance Method Details

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



698
699
700
# File 'lib/rbs/types.rb', line 698

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

#each_type(&block) ⇒ Object



733
734
735
736
737
738
739
# File 'lib/rbs/types.rb', line 733

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

#free_variables(set = Set.new) ⇒ Object



708
709
710
711
712
713
714
# File 'lib/rbs/types.rb', line 708

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)


760
761
762
# File 'lib/rbs/types.rb', line 760

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

#has_self_type?Boolean

Returns:

  • (Boolean)


756
757
758
# File 'lib/rbs/types.rb', line 756

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

#hashObject



704
705
706
# File 'lib/rbs/types.rb', line 704

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

#map_type(&block) ⇒ Object



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

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



749
750
751
752
753
754
# File 'lib/rbs/types.rb', line 749

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

#sub(s) ⇒ Object



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

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

#to_json(state = _ = nil) ⇒ Object



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

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

#to_s(level = 0) ⇒ Object



725
726
727
728
729
730
731
# File 'lib/rbs/types.rb', line 725

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

#with_nonreturn_void?Boolean

Returns:

  • (Boolean)


764
765
766
# File 'lib/rbs/types.rb', line 764

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