Class: RBS::Types::Intersection
- Inherits:
-
Object
- Object
- RBS::Types::Intersection
- 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:) ⇒ Intersection
constructor
A new instance of Intersection.
- #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:) ⇒ Intersection
Returns a new instance of Intersection.
826 827 828 829 |
# File 'lib/rbs/types.rb', line 826 def initialize(types:, location:) @types = types @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
824 825 826 |
# File 'lib/rbs/types.rb', line 824 def location @location end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
823 824 825 |
# File 'lib/rbs/types.rb', line 823 def types @types end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
831 832 833 |
# File 'lib/rbs/types.rb', line 831 def ==(other) other.is_a?(Intersection) && other.types == types end |
#each_type(&block) ⇒ Object
869 870 871 872 873 874 875 |
# File 'lib/rbs/types.rb', line 869 def each_type(&block) if block types.each(&block) else enum_for :each_type end end |
#free_variables(set = Set.new) ⇒ Object
841 842 843 844 845 846 847 |
# File 'lib/rbs/types.rb', line 841 def free_variables(set = Set.new) set.tap do types.each do |type| type.free_variables set end end end |
#has_classish_type? ⇒ Boolean
896 897 898 |
# File 'lib/rbs/types.rb', line 896 def has_classish_type? each_type.any? {|type| type.has_classish_type? } end |
#has_self_type? ⇒ Boolean
892 893 894 |
# File 'lib/rbs/types.rb', line 892 def has_self_type? each_type.any? {|type| type.has_self_type? } end |
#hash ⇒ Object
837 838 839 |
# File 'lib/rbs/types.rb', line 837 def hash self.class.hash ^ types.hash end |
#map_type(&block) ⇒ Object
877 878 879 880 881 882 883 |
# File 'lib/rbs/types.rb', line 877 def map_type(&block) if block Intersection.new(types: types.map(&block), location: location) else enum_for :map_type end end |
#map_type_name(&block) ⇒ Object
885 886 887 888 889 890 |
# File 'lib/rbs/types.rb', line 885 def map_type_name(&block) Intersection.new( types: types.map {|type| type.map_type_name(&block) }, location: location ) end |
#sub(s) ⇒ Object
853 854 855 856 857 858 |
# File 'lib/rbs/types.rb', line 853 def sub(s) return self if s.empty? self.class.new(types: types.map {|ty| ty.sub(s) }, location: location) end |
#to_json(state = _ = nil) ⇒ Object
849 850 851 |
# File 'lib/rbs/types.rb', line 849 def to_json(state = _ = nil) { class: :intersection, types: types, location: location }.to_json(state) end |
#to_s(level = 0) ⇒ Object
860 861 862 863 864 865 866 867 |
# File 'lib/rbs/types.rb', line 860 def to_s(level = 0) strs = types.map {|ty| ty.to_s(2) } if level > 0 "(#{strs.join(" & ")})" else strs.join(" & ") end end |
#with_nonreturn_void? ⇒ Boolean
900 901 902 |
# File 'lib/rbs/types.rb', line 900 def with_nonreturn_void? each_type.any? {|type| type.with_nonreturn_void? } end |