Class: RBS::Types::Union
- Inherits:
-
Object
- Object
- RBS::Types::Union
- Defined in:
- lib/rbs/types.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #each_type(&block) ⇒ Object
- #free_variables(set = Set.new) ⇒ Object
- #has_classish_type? ⇒ Boolean
- #has_self_type? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(types:, location:) ⇒ Union
constructor
A new instance of Union.
- #map_type(&block) ⇒ Object
- #map_type_name(&block) ⇒ Object
- #sub(s) ⇒ Object
- #to_json(state = _ = nil) ⇒ Object
- #to_s(level = 0) ⇒ Object
- #with_nonreturn_void? ⇒ Boolean
Constructor Details
#initialize(types:, location:) ⇒ Union
Returns a new instance of Union.
721 722 723 724 |
# File 'lib/rbs/types.rb', line 721 def initialize(types:, location:) @types = types @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
719 720 721 |
# File 'lib/rbs/types.rb', line 719 def location @location end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
718 719 720 |
# File 'lib/rbs/types.rb', line 718 def types @types end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
726 727 728 |
# File 'lib/rbs/types.rb', line 726 def ==(other) other.is_a?(Union) && other.types == types end |
#each_type(&block) ⇒ Object
761 762 763 764 765 766 767 |
# File 'lib/rbs/types.rb', line 761 def each_type(&block) if block types.each(&block) else enum_for :each_type end end |
#free_variables(set = Set.new) ⇒ Object
736 737 738 739 740 741 742 |
# File 'lib/rbs/types.rb', line 736 def free_variables(set = Set.new) set.tap do types.each do |type| type.free_variables set end end end |
#has_classish_type? ⇒ Boolean
788 789 790 |
# File 'lib/rbs/types.rb', line 788 def has_classish_type? each_type.any? {|type| type.has_classish_type? } end |
#has_self_type? ⇒ Boolean
784 785 786 |
# File 'lib/rbs/types.rb', line 784 def has_self_type? each_type.any? {|type| type.has_self_type? } end |
#hash ⇒ Object
732 733 734 |
# File 'lib/rbs/types.rb', line 732 def hash self.class.hash ^ types.hash end |
#map_type(&block) ⇒ Object
769 770 771 772 773 774 775 |
# File 'lib/rbs/types.rb', line 769 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
777 778 779 780 781 782 |
# File 'lib/rbs/types.rb', line 777 def map_type_name(&block) Union.new( types: types.map {|type| type.map_type_name(&block) }, location: location ) end |
#sub(s) ⇒ Object
748 749 750 751 |
# File 'lib/rbs/types.rb', line 748 def sub(s) self.class.new(types: types.map {|ty| ty.sub(s) }, location: location) end |
#to_json(state = _ = nil) ⇒ Object
744 745 746 |
# File 'lib/rbs/types.rb', line 744 def to_json(state = _ = nil) { class: :union, types: types, location: location }.to_json(state) end |
#to_s(level = 0) ⇒ Object
753 754 755 756 757 758 759 |
# File 'lib/rbs/types.rb', line 753 def to_s(level = 0) if level > 0 "(#{types.join(" | ")})" else types.join(" | ") end end |
#with_nonreturn_void? ⇒ Boolean
792 793 794 |
# File 'lib/rbs/types.rb', line 792 def with_nonreturn_void? each_type.any? {|type| type.with_nonreturn_void? } end |