class Prism::MatchRequiredNode
表示 => 运算符的使用。
foo => bar ^^^^^^^^^^
属性
表示运算符的右侧。节点的类型取决于表达式。
任何看起来像局部变量名(包括 _)的内容都会导致生成 LocalVariableTargetNode。
foo => a # This is equivalent to writing `a = foo`
^
使用显式的 Array 或将表达式与 , 组合将导致生成 ArrayPatternNode。这可以由常量前置。
foo => [a]
^^^
foo => a, b
^^^^
foo => Bar[a, b]
^^^^^^^^^
如果数组模式包含至少两个通配符匹配,则会创建一个 FindPatternNode。
foo => *, 1, *a
^^^^^
使用显式的 Hash 或带方括号的常量和方括号内的哈希键将导致生成 HashPatternNode。
foo => { a: 1, b: } foo => Bar[a: 1, b:] foo => Bar[**]
要使用任何需要运行时求值的变量,需要进行固定。这会导致生成 PinnedVariableNode。
foo => ^a
^^
类似地,任何表达式都可以与固定一起使用。这会导致生成 PinnedExpressionNode。
foo => ^(a + 1)
其他任何内容都会导致生成该表达式的常规节点,例如 ConstantReadNode。
foo => CONST
表示运算符的左侧。
foo => bar ^^^
Public Class Methods
Source
# File lib/prism/node.rb, line 12780 def initialize(source, node_id, location, flags, value, pattern, operator_loc) @source = source @node_id = node_id @location = location @flags = flags @value = value @pattern = pattern @operator_loc = operator_loc end
初始化一个新的 MatchRequiredNode 节点。
Source
# File lib/prism/node.rb, line 12906 def self.type :match_required_node end
返回此节点类型的符号表示。参见 Node::type。
Public Instance Methods
Source
# File lib/prism/node.rb, line 12912 def ===(other) other.is_a?(MatchRequiredNode) && (value === other.value) && (pattern === other.pattern) && (operator_loc.nil? == other.operator_loc.nil?) end
实现节点的相等性判断。这实际上是 ==,但不比较 location 的值。仅检查 location 是否存在。
Source
# File lib/prism/node.rb, line 12791 def accept(visitor) visitor.visit_match_required_node(self) end
def accept: (Visitor visitor) -> void
Source
# File lib/prism/node.rb, line 12796 def child_nodes [value, pattern] end
def child_nodes: () -> Array
Source
# File lib/prism/node.rb, line 12806 def comment_targets [value, pattern, operator_loc] #: Array[Prism::node | Location] end
def comment_targets: () -> Array[Node | Location]
Source
# File lib/prism/node.rb, line 12801 def compact_child_nodes [value, pattern] end
def compact_child_nodes: () -> Array
Source
# File lib/prism/node.rb, line 12811 def copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, pattern: self.pattern, operator_loc: self.operator_loc) MatchRequiredNode.new(source, node_id, location, flags, value, pattern, operator_loc) end
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?value: Prism::node, ?pattern: Prism::node, ?operator_loc: Location) -> MatchRequiredNode
Source
# File lib/prism/node.rb, line 12819 def deconstruct_keys(keys) { node_id: node_id, location: location, value: value, pattern: pattern, operator_loc: operator_loc } end
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, value: Prism::node, pattern: Prism::node, operator_loc: Location }
Source
# File lib/prism/node.rb, line 12896 def inspect InspectVisitor.compose(self) end
def inspect -> String
Source
# File lib/prism/node.rb, line 12891 def operator operator_loc.slice end
def operator: () -> String
Source
# File lib/prism/node.rb, line 12878 def operator_loc location = @operator_loc return location if location.is_a?(Location) @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end
运算符的位置。
foo => bar
^^
Source
# File lib/prism/node.rb, line 12886 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end
使用给定的已保存源来保存 operator_loc 位置,以便以后可以检索它。