Class: Stone::AST::UnionTypeAnnotation
- Inherits:
-
Stone::AST
- Object
- Stone::AST
- Stone::AST::UnionTypeAnnotation
- Defined in:
- lib/stone/ast/union_type_annotation.rb
Instance Attribute Summary collapse
-
#alternatives ⇒ Object
readonly
Returns the value of attribute alternatives.
Attributes inherited from Stone::AST
Instance Method Summary collapse
-
#initialize(alternatives) ⇒ UnionTypeAnnotation
constructor
A new instance of UnionTypeAnnotation.
- #to_s ⇒ Object
- #to_type(registry) ⇒ Object
Constructor Details
#initialize(alternatives) ⇒ UnionTypeAnnotation
10 11 12 13 |
# File 'lib/stone/ast/union_type_annotation.rb', line 10 def initialize(alternatives) @alternatives = alternatives @name = :union_type_annotation end |
Instance Attribute Details
#alternatives ⇒ Object (readonly)
Returns the value of attribute alternatives.
8 9 10 |
# File 'lib/stone/ast/union_type_annotation.rb', line 8 def alternatives @alternatives end |
Instance Method Details
#to_s ⇒ Object
15 16 17 |
# File 'lib/stone/ast/union_type_annotation.rb', line 15 def to_s @alternatives.map(&:to_s).join(" | ") end |
#to_type(registry) ⇒ Object
19 20 21 22 |
# File 'lib/stone/ast/union_type_annotation.rb', line 19 def to_type(registry) alternative_types = @alternatives.map { |t| t.to_type(registry) }.compact Stone::Type.union(alternatives: alternative_types) end |