Class: Literal::Types::IntersectionType Private
- Inherits:
-
Object
- Object
- Literal::Types::IntersectionType
- Includes:
- Literal::Type
- Defined in:
- lib/literal/types/intersection_type.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #types ⇒ Object readonly private
Instance Method Summary collapse
- #===(value) ⇒ Object private
- #>=(other) ⇒ Object private
-
#initialize(types) ⇒ IntersectionType
constructor
private
A new instance of IntersectionType.
- #inspect ⇒ Object private
- #nil? ⇒ Boolean private
- #record_literal_type_errors(context) ⇒ Object private
Constructor Details
#initialize(types) ⇒ IntersectionType
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of IntersectionType.
7 8 9 10 11 12 |
# File 'lib/literal/types/intersection_type.rb', line 7 def initialize(types) raise Literal::ArgumentError.new("_Intersection type must have at least one type.") if types.size < 1 @types = types freeze end |
Instance Attribute Details
#types ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 |
# File 'lib/literal/types/intersection_type.rb', line 14 def types @types end |
Instance Method Details
#===(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
18 19 20 |
# File 'lib/literal/types/intersection_type.rb', line 18 def ===(value) @types.all? { |type| type === value } end |
#>=(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/literal/types/intersection_type.rb', line 34 def >=(other) case other when Literal::Types::IntersectionType @types.all? do |type| other.types.any? do |other_type| Literal.subtype?(other_type, type) end end when Literal::Types::ConstraintType @types.all? do |type| other.object_constraints.any? do |object_constraint| Literal.subtype?(object_constraint, type) end end when Literal::Types::FrozenType @types.all? { |type| Literal.subtype?(other.type, type) } else false end end |
#inspect ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 |
# File 'lib/literal/types/intersection_type.rb', line 16 def inspect = "_Intersection(#{@types.map(&:inspect).join(', ')})" |
#nil? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 |
# File 'lib/literal/types/intersection_type.rb', line 22 def nil? @types.all?(&:nil?) end |
#record_literal_type_errors(context) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 29 30 31 32 |
# File 'lib/literal/types/intersection_type.rb', line 26 def record_literal_type_errors(context) @types.each do |type| next if type === context.actual context.add_child(label: inspect, expected: type, actual: context.actual) end end |