class Prism::LocalVariableReadNode
表示读取局部变量。请注意,这要求在同一作用域中已经写入了具有相同名称的局部变量,否则它将被解析为方法调用。
foo ^^^
属性
应该搜索以找到此局部变量来源的可见作用域的数量。
foo = 1; foo # depth 0 bar = 2; tap { bar } # depth 1
计算深度 的具体规则可能因各个 Ruby 实现而异,因为语言没有指定这些规则。有关更多信息,请参阅 [Prism
文档](github.com/ruby/prism/blob/main/docs/local_variable_depth.md)。
局部变量的名称,这是一个[标识符](github.com/ruby/prism/blob/main/docs/parsing_rules.md#identifiers)。
x # name `:x` _Test # name `:_Test`
请注意,对于默认块参数,这也可以是下划线后跟一个数字。
_1 # name `:_1`
公共类方法
来源
# File lib/prism/node.rb, line 12037 def initialize(source, node_id, location, flags, name, depth) @source = source @node_id = node_id @location = location @flags = flags @name = name @depth = depth end
初始化一个新的 LocalVariableReadNode
节点。
来源
# File lib/prism/node.rb, line 12110 def self.type :local_variable_read_node end
返回此节点类型的符号表示形式。请参阅 ‘Node::type`。
公共实例方法
来源
# File lib/prism/node.rb, line 12116 def ===(other) other.is_a?(LocalVariableReadNode) && (name === other.name) && (depth === other.depth) end
为节点实现 case-equality。这实际上是 ==,但不比较位置的值。位置仅检查是否存在。
来源
# File lib/prism/node.rb, line 12047 def accept(visitor) visitor.visit_local_variable_read_node(self) end
def accept: (Visitor
visitor) -> void
来源
# File lib/prism/node.rb, line 12052 def child_nodes [] end
def child_nodes
: () -> Array[nil | Node]
来源
# File lib/prism/node.rb, line 12062 def comment_targets [] #: Array[Prism::node | Location] end
def comment_targets
: () -> Array[Node | Location]
来源
# File lib/prism/node.rb, line 12057 def compact_child_nodes [] end
def compact_child_nodes
: () -> Array
来源
# File lib/prism/node.rb, line 12067 def copy(node_id: self.node_id, location: self.location, flags: self.flags, name: self.name, depth: self.depth) LocalVariableReadNode.new(source, node_id, location, flags, name, depth) end
def copy: (?node_id: Integer
, ?location: Location
, ?flags: Integer
, ?name: Symbol
, ?depth: Integer
) -> LocalVariableReadNode
来源
来源
# File lib/prism/node.rb, line 12100 def inspect InspectVisitor.compose(self) end
def inspect -> String
来源
# File lib/prism/node.rb, line 12105 def type :local_variable_read_node end
返回此节点类型的符号表示形式。请参阅 ‘Node#type`。