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.



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

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

Instance Attribute Details

#valueObject (readonly)

String

the # used in the string



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

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



5167
5168
5169
# File 'lib/syntax_tree/node.rb', line 5167

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

#accept(visitor) ⇒ Object



5146
5147
5148
# File 'lib/syntax_tree/node.rb', line 5146

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

#child_nodesObject Also known as: deconstruct



5150
5151
5152
# File 'lib/syntax_tree/node.rb', line 5150

def child_nodes
  []
end

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



5154
5155
5156
5157
5158
5159
# File 'lib/syntax_tree/node.rb', line 5154

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

#deconstruct_keys(_keys) ⇒ Object



5163
5164
5165
# File 'lib/syntax_tree/node.rb', line 5163

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