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 ^^^
公共类方法
初始化一个新的 UnlessNode
节点。
# File 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
返回此节点类型的符号表示。请参见 “Node::type`。
# File prism/node.rb, line 17664 def self.type :unless_node end
公共实例方法
为节点实现 case 相等性。这实际上是 ==,但不比较位置的值。仅检查位置是否存在。
# File 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
def accept: (Visitor
visitor) -> void
# File prism/node.rb, line 17517 def accept(visitor) visitor.visit_unless_node(self) end
def child_nodes
: () -> Array[nil | Node]
# File prism/node.rb, line 17522 def child_nodes [predicate, statements, else_clause] end
def comment_targets
: () -> Array[Node | Location]
# File 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 compact_child_nodes
: () -> Array
# File 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
返回 unless 节点的 else 子句。此方法已弃用,建议使用 else_clause
。
# File prism/node_ext.rb, line 503 def consequent deprecated("else_clause") else_clause 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 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 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 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 end_keyword
: () -> String?
# File prism/node.rb, line 17649 def end_keyword end_keyword_loc&.slice end
‘end` 关键字的位置(如果存在)。
unless cond then bar end ^^^
# File 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
def inspect -> String
# File prism/node.rb, line 17654 def inspect InspectVisitor.compose(self) end
def keyword: () -> String
# File prism/node.rb, line 17639 def keyword keyword_loc.slice end
‘unless` 关键字的位置。
unless cond then bar end ^^^^^^ bar unless cond ^^^^^^
# File 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
使用给定的保存源保存 end_keyword_loc
位置,以便以后检索。
# File prism/node.rb, line 17634 def save_end_keyword_loc(repository) repository.enter(node_id, :end_keyword_loc) unless @end_keyword_loc.nil? end
使用给定的保存源保存 keyword_loc
位置,以便以后检索。
# File prism/node.rb, line 17568 def save_keyword_loc(repository) repository.enter(node_id, :keyword_loc) end
使用给定的保存源保存 then_keyword_loc
位置,以便以后检索。
# File prism/node.rb, line 17599 def save_then_keyword_loc(repository) repository.enter(node_id, :then_keyword_loc) unless @then_keyword_loc.nil? end
def then_keyword
: () -> String?
# File prism/node.rb, line 17644 def then_keyword then_keyword_loc&.slice end
‘then` 关键字的位置(如果存在)。
unless cond then bar end ^^^^
# File 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
返回此节点类型的符号表示。请参见 “Node#type`。
# File prism/node.rb, line 17659 def type :unless_node end