Class: Cyrel::AST::LiteralNode
- Inherits:
-
Data
- Object
- Data
- Cyrel::AST::LiteralNode
- 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
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
-
#deconstruct ⇒ Object
Pattern matching support.
- #deconstruct_keys(_keys) ⇒ Object
-
#inferred_type ⇒ Object
Type inference.
- #to_ast ⇒ Object
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute 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 |
#deconstruct ⇒ Object
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_type ⇒ Object
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_ast ⇒ Object
12 13 14 |
# File 'lib/cyrel/ast/literal_node.rb', line 12 def to_ast self end |