Class: Stone::AST::UnionTypeAnnotation

Inherits:
Stone::AST
  • Object
show all
Defined in:
lib/stone/ast/union_type_annotation.rb

Instance Attribute Summary collapse

Attributes inherited from Stone::AST

#children, #name

Instance Method Summary collapse

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

#alternativesObject (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_sObject



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