Class: Prism::EmbeddedVariableNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
ext/prism/api_node.c

Overview

Represents an interpolated variable.

"foo #@bar"
     ^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, operator_loc, variable) ⇒ EmbeddedVariableNode

Initialize a new EmbeddedVariableNode node.



6532
6533
6534
6535
6536
6537
6538
6539
# File 'lib/prism/node.rb', line 6532

def initialize(source, node_id, location, flags, operator_loc, variable)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @operator_loc = operator_loc
  @variable = variable
end

Instance Attribute Details

#variableObject (readonly)

attr_reader variable: InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode



6588
6589
6590
# File 'lib/prism/node.rb', line 6588

def variable
  @variable
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



6606
6607
6608
# File 'lib/prism/node.rb', line 6606

def self.type
  :embedded_variable_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



6612
6613
6614
6615
6616
# File 'lib/prism/node.rb', line 6612

def ===(other)
  other.is_a?(EmbeddedVariableNode) &&
    (operator_loc.nil? == other.operator_loc.nil?) &&
    (variable === other.variable)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



6542
6543
6544
# File 'lib/prism/node.rb', line 6542

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



6547
6548
6549
# File 'lib/prism/node.rb', line 6547

def child_nodes
  [variable]
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



6557
6558
6559
# File 'lib/prism/node.rb', line 6557

def comment_targets
  [operator_loc, variable] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



6552
6553
6554
# File 'lib/prism/node.rb', line 6552

def compact_child_nodes
  [variable]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, operator_loc: self.operator_loc, variable: self.variable) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?operator_loc: Location, ?variable: InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode) -> EmbeddedVariableNode



6562
6563
6564
# File 'lib/prism/node.rb', line 6562

def copy(node_id: self.node_id, location: self.location, flags: self.flags, operator_loc: self.operator_loc, variable: self.variable)
  EmbeddedVariableNode.new(source, node_id, location, flags, operator_loc, variable)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, operator_loc: Location, variable: InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode }



6570
6571
6572
# File 'lib/prism/node.rb', line 6570

def deconstruct_keys(keys)
  { node_id: node_id, location: location, operator_loc: operator_loc, variable: variable }
end

#inspectObject

def inspect -> String



6596
6597
6598
# File 'lib/prism/node.rb', line 6596

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



6591
6592
6593
# File 'lib/prism/node.rb', line 6591

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



6575
6576
6577
6578
6579
# File 'lib/prism/node.rb', line 6575

def operator_loc
  location = @operator_loc
  return location if location.is_a?(Location)
  @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#save_operator_loc(repository) ⇒ Object

Save the operator_loc location using the given saved source so that it can be retrieved later.



6583
6584
6585
# File 'lib/prism/node.rb', line 6583

def save_operator_loc(repository)
  repository.enter(node_id, :operator_loc)
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



6601
6602
6603
# File 'lib/prism/node.rb', line 6601

def type
  :embedded_variable_node
end