Class: Literal::Types::UnionType
- Inherits:
-
Object
- Object
- Literal::Types::UnionType
- Includes:
- Enumerable
- Defined in:
- lib/literal/types/union_type.rb
Instance Method Summary collapse
- #===(value) ⇒ Object
- #deconstruct ⇒ Object
- #each ⇒ Object
-
#initialize(*types) ⇒ UnionType
constructor
A new instance of UnionType.
- #inspect ⇒ Object
- #load_types(types) ⇒ Object private
Constructor Details
#initialize(*types) ⇒ UnionType
Returns a new instance of UnionType.
6 7 8 9 10 11 12 |
# File 'lib/literal/types/union_type.rb', line 6 def initialize(*types) raise Literal::ArgumentError.new("_Union type must have at least one type.") if types.size < 1 @types = Set[] load_types(types) @types.freeze end |
Instance Method Details
#===(value) ⇒ Object
16 17 18 |
# File 'lib/literal/types/union_type.rb', line 16 def ===(value) @types.any? { |type| type === value } end |
#deconstruct ⇒ Object
24 25 26 |
# File 'lib/literal/types/union_type.rb', line 24 def deconstruct @types.to_a end |
#each ⇒ Object
20 21 22 |
# File 'lib/literal/types/union_type.rb', line 20 def each(&) @types.each(&) end |
#inspect ⇒ Object
14 |
# File 'lib/literal/types/union_type.rb', line 14 def inspect = "_Union(#{@types.inspect})" |