Class: YARP::EmbeddedVariableNode

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

Overview

Represents an interpolated variable.

"foo #@bar"
     ^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operator_loc, variable, location) ⇒ EmbeddedVariableNode

def initialize: (operator_loc: Location, variable: Node, location: Location) -> void



3816
3817
3818
3819
3820
# File 'lib/yarp/node.rb', line 3816

def initialize(operator_loc, variable, location)
  @operator_loc = operator_loc
  @variable = variable
  @location = location
end

Instance Attribute Details

#operator_locObject (readonly)

attr_reader operator_loc: Location



3810
3811
3812
# File 'lib/yarp/node.rb', line 3810

def operator_loc
  @operator_loc
end

#variableObject (readonly)

attr_reader variable: Node



3813
3814
3815
# File 'lib/yarp/node.rb', line 3813

def variable
  @variable
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



3823
3824
3825
# File 'lib/yarp/node.rb', line 3823

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

#child_nodesObject Also known as: deconstruct

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



3828
3829
3830
# File 'lib/yarp/node.rb', line 3828

def child_nodes
  [variable]
end

#comment_targetsObject

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



3833
3834
3835
# File 'lib/yarp/node.rb', line 3833

def comment_targets
  [operator_loc, variable]
end

#copy(**params) ⇒ Object

def copy: (**params) -> EmbeddedVariableNode



3838
3839
3840
3841
3842
3843
3844
# File 'lib/yarp/node.rb', line 3838

def copy(**params)
  EmbeddedVariableNode.new(
    params.fetch(:operator_loc) { operator_loc },
    params.fetch(:variable) { variable },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



3850
3851
3852
# File 'lib/yarp/node.rb', line 3850

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

#inspect(inspector = NodeInspector.new) ⇒ Object



3859
3860
3861
3862
3863
3864
3865
# File 'lib/yarp/node.rb', line 3859

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n"
  inspector << "└── variable:\n"
  inspector << inspector.child_node(variable, "    ")
  inspector.to_str
end

#operatorObject

def operator: () -> String



3855
3856
3857
# File 'lib/yarp/node.rb', line 3855

def operator
  operator_loc.slice
end