Class: Yoda::Typing::Types::Union
- Defined in:
- lib/yoda/typing/types/union.rb
Instance Attribute Summary collapse
- #types ⇒ Array<Base> readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*types) ⇒ Union
constructor
A new instance of Union.
- #to_expression ⇒ Object
- #to_type_string ⇒ Object
Methods inherited from Base
Constructor Details
Instance Attribute Details
#types ⇒ Array<Base> (readonly)
6 7 8 |
# File 'lib/yoda/typing/types/union.rb', line 6 def types @types end |
Class Method Details
.new(*types) ⇒ Union, ...
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/yoda/typing/types/union.rb', line 10 def self.new(*types) extracted_types = types.map { |type| type.is_a?(Union) ? type.types : type }.flatten case extracted_types.length when 0 Any.new when 1 extracted_types.first else super(*extracted_types) end end |
Instance Method Details
#to_expression ⇒ Object
28 29 30 |
# File 'lib/yoda/typing/types/union.rb', line 28 def to_expression Model::TypeExpressions::UnionType.new(types.map(&:to_expression)) end |
#to_type_string ⇒ Object
32 33 34 |
# File 'lib/yoda/typing/types/union.rb', line 32 def to_type_string types.map(&:to_type_string).join(" | ") end |