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, #format, #pretty_print, #to_json

Constructor Details

#initialize(value:, location:) ⇒ EmbVar

Returns a new instance of EmbVar.



5019
5020
5021
5022
# File 'lib/syntax_tree/node.rb', line 5019

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

Instance Attribute Details

#valueObject (readonly)

String

the # used in the string



5017
5018
5019
# File 'lib/syntax_tree/node.rb', line 5017

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



5045
5046
5047
# File 'lib/syntax_tree/node.rb', line 5045

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

#accept(visitor) ⇒ Object



5024
5025
5026
# File 'lib/syntax_tree/node.rb', line 5024

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

#child_nodesObject Also known as: deconstruct



5028
5029
5030
# File 'lib/syntax_tree/node.rb', line 5028

def child_nodes
  []
end

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



5032
5033
5034
5035
5036
5037
# File 'lib/syntax_tree/node.rb', line 5032

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

#deconstruct_keys(_keys) ⇒ Object



5041
5042
5043
# File 'lib/syntax_tree/node.rb', line 5041

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