class Prism::UnlessNode
表示 `unless` 关键字的使用,可以是块形式或修饰符形式。
bar unless foo ^^^^^^^^^^^^^^ unless foo then bar end ^^^^^^^^^^^^^^^^^^^^^^^
属性
unless 表达式的 else 子句(如果存在)。
unless cond then bar else baz end ^^^^^^^^
用于 unless 表达式评估的条件。它可以是任何[非空表达式](github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression)。
unless cond then bar end ^^^^ bar unless cond ^^^^
如果 unless 条件为假,将执行的语句主体。如果没有提供主体,则为 `nil`。
unless cond then bar end ^^^
公共类方法
源代码
# File lib/prism/node.rb, line 17503 def initialize(source, node_id, location, flags, keyword_loc, predicate, then_keyword_loc, statements, else_clause, end_keyword_loc) @source = source @node_id = node_id @location = location @flags = flags @keyword_loc = keyword_loc @predicate = predicate @then_keyword_loc = then_keyword_loc @statements = statements @else_clause = else_clause @end_keyword_loc = end_keyword_loc end
初始化一个新的 UnlessNode
节点。
源代码
# File lib/prism/node.rb, line 17664 def self.type :unless_node end
返回此节点类型的符号表示。请参阅 `Node::type`。
公共实例方法
源代码
# File lib/prism/node.rb, line 17670 def ===(other) other.is_a?(UnlessNode) && (keyword_loc.nil? == other.keyword_loc.nil?) && (predicate === other.predicate) && (then_keyword_loc.nil? == other.then_keyword_loc.nil?) && (statements === other.statements) && (else_clause === other.else_clause) && (end_keyword_loc.nil? == other.end_keyword_loc.nil?) end
实现节点的 case-equality。这实际上是 ==,但不比较位置的值。位置仅检查是否存在。
源代码
# File lib/prism/node.rb, line 17517 def accept(visitor) visitor.visit_unless_node(self) end
def accept: (Visitor
visitor) -> void
源代码
# File lib/prism/node.rb, line 17522 def child_nodes [predicate, statements, else_clause] end
def child_nodes
: () -> Array[nil | Node]
源代码
# File lib/prism/node.rb, line 17536 def comment_targets [keyword_loc, predicate, *then_keyword_loc, *statements, *else_clause, *end_keyword_loc] #: Array[Prism::node | Location] end
def comment_targets
: () -> Array[Node | Location]
源代码
# File lib/prism/node.rb, line 17527 def compact_child_nodes compact = [] #: Array[Prism::node] compact << predicate compact << statements if statements compact << else_clause if else_clause compact end
def compact_child_nodes
: () -> Array
源代码
# File lib/prism/node_ext.rb, line 503 def consequent deprecated("else_clause") else_clause end
返回 unless 节点的 else 子句。此方法已被弃用,请使用 else_clause
。
源代码
# File lib/prism/node.rb, line 17541 def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, predicate: self.predicate, then_keyword_loc: self.then_keyword_loc, statements: self.statements, else_clause: self.else_clause, end_keyword_loc: self.end_keyword_loc) UnlessNode.new(source, node_id, location, flags, keyword_loc, predicate, then_keyword_loc, statements, else_clause, end_keyword_loc) end
def copy: (?node_id: Integer
, ?location: Location
, ?flags: Integer
, ?keyword_loc: Location
, ?predicate: Prism::node, ?then_keyword_loc: Location
?, ?statements: StatementsNode
?, ?else_clause: ElseNode
?, ?end_keyword_loc: Location
?) -> UnlessNode
源代码
# File lib/prism/node.rb, line 17549 def deconstruct_keys(keys) { node_id: node_id, location: location, keyword_loc: keyword_loc, predicate: predicate, then_keyword_loc: then_keyword_loc, statements: statements, else_clause: else_clause, end_keyword_loc: end_keyword_loc } end
def deconstruct_keys
: (Array keys) -> { node_id: Integer
, location: Location
, keyword_loc
: Location
, predicate: Prism::node, then_keyword_loc
: Location
?, statements: StatementsNode
?, else_clause
: ElseNode
?, end_keyword_loc
: Location
? }
源代码
# File lib/prism/node.rb, line 17649 def end_keyword end_keyword_loc&.slice end
def end_keyword
: () -> String
?
源代码
# File lib/prism/node.rb, line 17620 def end_keyword_loc location = @end_keyword_loc case location when nil nil when Location location else @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end
表示 `end` 关键字的位置(如果存在)。
unless cond then bar end ^^^
源代码
# File lib/prism/node.rb, line 17654 def inspect InspectVisitor.compose(self) end
def inspect -> String
源代码
# File lib/prism/node.rb, line 17639 def keyword keyword_loc.slice end
def keyword: () -> String
源代码
# File lib/prism/node.rb, line 17560 def keyword_loc location = @keyword_loc return location if location.is_a?(Location) @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end
表示 `unless` 关键字的位置。
unless cond then bar end ^^^^^^ bar unless cond ^^^^^^
源代码
# File lib/prism/node.rb, line 17634 def save_end_keyword_loc(repository) repository.enter(node_id, :end_keyword_loc) unless @end_keyword_loc.nil? end
使用给定的保存源保存 end_keyword_loc
位置,以便稍后检索。
源代码
# File lib/prism/node.rb, line 17568 def save_keyword_loc(repository) repository.enter(node_id, :keyword_loc) end
使用给定的保存源保存 keyword_loc
位置,以便稍后检索。
源代码
# File lib/prism/node.rb, line 17599 def save_then_keyword_loc(repository) repository.enter(node_id, :then_keyword_loc) unless @then_keyword_loc.nil? end
使用给定的保存源保存 then_keyword_loc
位置,以便稍后检索。
源代码
# File lib/prism/node.rb, line 17644 def then_keyword then_keyword_loc&.slice end
def then_keyword
: () -> String
?
源代码
# File lib/prism/node.rb, line 17585 def then_keyword_loc location = @then_keyword_loc case location when nil nil when Location location else @then_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end
表示 `then` 关键字的位置(如果存在)。
unless cond then bar end ^^^^
源代码
# File lib/prism/node.rb, line 17659 def type :unless_node end
返回此节点类型的符号表示。请参阅 `Node#type`。