Class: SyntaxTree::EmbVar

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

EmbVar represents the use of shorthand interpolation for an instance, class, or global variable into a parent node that accepts string content (like a string or regular expression).

"#@variable"

In the example above, an EmbVar node represents the # because it forces

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #end_char, #format, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(value:, location:) ⇒ EmbVar

Returns a new instance of EmbVar.



5126
5127
5128
5129
# File 'lib/syntax_tree/node.rb', line 5126

def initialize(value:, location:)
  @value = value
  @location = location
end

Instance Attribute Details

#valueObject (readonly)

String

the # used in the string



5124
5125
5126
# File 'lib/syntax_tree/node.rb', line 5124

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



5152
5153
5154
# File 'lib/syntax_tree/node.rb', line 5152

def ===(other)
  other.is_a?(EmbVar) && value === other.value
end

#accept(visitor) ⇒ Object



5131
5132
5133
# File 'lib/syntax_tree/node.rb', line 5131

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

#child_nodesObject Also known as: deconstruct



5135
5136
5137
# File 'lib/syntax_tree/node.rb', line 5135

def child_nodes
  []
end

#copy(value: nil, location: nil) ⇒ Object



5139
5140
5141
5142
5143
5144
# File 'lib/syntax_tree/node.rb', line 5139

def copy(value: nil, location: nil)
  EmbVar.new(
    value: value || self.value,
    location: location || self.location
  )
end

#deconstruct_keys(_keys) ⇒ Object



5148
5149
5150
# File 'lib/syntax_tree/node.rb', line 5148

def deconstruct_keys(_keys)
  { value: value, location: location }
end