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.
693 694 695 696 |
# File 'lib/rbs/types.rb', line 693 def initialize(types:, location:) @types = types @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
691 692 693 |
# File 'lib/rbs/types.rb', line 691 def location @location end |
#types ⇒ Object (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
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
756 757 758 |
# File 'lib/rbs/types.rb', line 756 def has_self_type? each_type.any? {|type| type.has_self_type? } end |
#hash ⇒ Object
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
764 765 766 |
# File 'lib/rbs/types.rb', line 764 def with_nonreturn_void? each_type.any? {|type| type.with_nonreturn_void? } end |