class T::Types::Intersection
Takes a list of types. Validates that an object matches all of the types.
Attributes
types[R]
Public Class Methods
new(types)
click to toggle source
# File lib/types/types/intersection.rb, line 9 def initialize(types) @types = types.flat_map do |type| type = T::Utils.resolve_alias(type) if type.is_a?(Intersection) # Simplify nested intersections (mostly so `name` returns a nicer value) type.types else T::Utils.coerce(type) end end.uniq end
Public Instance Methods
name()
click to toggle source
@override Base
# File lib/types/types/intersection.rb, line 22 def name "T.all(#{@types.map(&:name).sort.join(', ')})" end
recursively_valid?(obj)
click to toggle source
@override Base
# File lib/types/types/intersection.rb, line 27 def recursively_valid?(obj) @types.all? {|type| type.recursively_valid?(obj)} end
valid?(obj)
click to toggle source
@override Base
# File lib/types/types/intersection.rb, line 32 def valid?(obj) @types.all? {|type| type.valid?(obj)} end
Private Instance Methods
subtype_of_single?(other)
click to toggle source
@override Base
# File lib/types/types/intersection.rb, line 37 def subtype_of_single?(other) raise "This should never be reached if you're going through `subtype_of?` (and you should be)" end