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.
714 715 716 717 |
# File 'lib/rbs/types.rb', line 714 def initialize(types:, location:) @types = types @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
712 713 714 |
# File 'lib/rbs/types.rb', line 712 def location @location end |
#types ⇒ Object (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
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
777 778 779 |
# File 'lib/rbs/types.rb', line 777 def has_self_type? each_type.any? {|type| type.has_self_type? } end |
#hash ⇒ Object
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
785 786 787 |
# File 'lib/rbs/types.rb', line 785 def with_nonreturn_void? each_type.any? {|type| type.with_nonreturn_void? } end |