Class: Cyrel::AST::LiteralNode

Inherits:
Data
  • Object
show all
Defined in:
lib/cyrel/ast/literal_node.rb

Overview

Immutable AST node for literal values using Ruby’s Data class Because sometimes you just want to say what you mean, immutably

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



7
8
9
# File 'lib/cyrel/ast/literal_node.rb', line 7

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



8
9
10
# File 'lib/cyrel/ast/literal_node.rb', line 8

def accept(visitor)
  visitor.visit_literal_node(self)
end

#deconstructObject

Pattern matching support



17
18
19
# File 'lib/cyrel/ast/literal_node.rb', line 17

def deconstruct
  [value]
end

#deconstruct_keys(_keys) ⇒ Object



21
22
23
# File 'lib/cyrel/ast/literal_node.rb', line 21

def deconstruct_keys(_keys)
  { value: value }
end

#inferred_typeObject

Type inference



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cyrel/ast/literal_node.rb', line 26

def inferred_type
  case value
  when String then :string
  when Symbol then :parameter
  when Integer then :integer
  when Float then :float
  when TrueClass, FalseClass then :boolean
  when NilClass then :null
  else :unknown
  end
end

#to_astObject



12
13
14
# File 'lib/cyrel/ast/literal_node.rb', line 12

def to_ast
  self
end