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.



5662
5663
5664
5665
5666
5667
5668
5669
# File 'lib/prism/node.rb', line 5662

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: Prism::node



5712
5713
5714
# File 'lib/prism/node.rb', line 5712

def variable
  @variable
end

Class Method Details

.typeObject

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



5730
5731
5732
# File 'lib/prism/node.rb', line 5730

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.



5736
5737
5738
5739
5740
# File 'lib/prism/node.rb', line 5736

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



5672
5673
5674
# File 'lib/prism/node.rb', line 5672

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

#child_nodesObject Also known as: deconstruct

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



5677
5678
5679
# File 'lib/prism/node.rb', line 5677

def child_nodes
  [variable]
end

#comment_targetsObject

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



5687
5688
5689
# File 'lib/prism/node.rb', line 5687

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



5682
5683
5684
# File 'lib/prism/node.rb', line 5682

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: Prism::node) -> EmbeddedVariableNode



5692
5693
5694
# File 'lib/prism/node.rb', line 5692

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: Prism::node }



5700
5701
5702
# File 'lib/prism/node.rb', line 5700

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

#inspectObject

def inspect -> String



5720
5721
5722
# File 'lib/prism/node.rb', line 5720

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



5715
5716
5717
# File 'lib/prism/node.rb', line 5715

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



5705
5706
5707
5708
5709
# File 'lib/prism/node.rb', line 5705

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

#typeObject

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



5725
5726
5727
# File 'lib/prism/node.rb', line 5725

def type
  :embedded_variable_node
end