class Prism::CaseNode

表示 case 语句的使用。

case true
when false
end
^^^^^^^^^^

属性

conditions[R]

表示 case 语句的条件。

case true; when false; end
           ^^^^^^^^^^
else_clause[R]

表示 case 语句的 else 子句。

case true; when false; else; end
                       ^^^^
predicate[R]

表示 case 语句的谓词。这可以是 ‘nil` 或任何[非 void 表达式](github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression)。

case true; when false; end
^^^^

公共类方法

new(source, node_id, location, flags, predicate, conditions, else_clause, case_keyword_loc, end_keyword_loc) 点击切换源代码

初始化一个新的 CaseNode 节点。

# File prism/node.rb, line 3671
def initialize(source, node_id, location, flags, predicate, conditions, else_clause, case_keyword_loc, end_keyword_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @predicate = predicate
  @conditions = conditions
  @else_clause = else_clause
  @case_keyword_loc = case_keyword_loc
  @end_keyword_loc = end_keyword_loc
end
type() 点击切换源代码

返回此节点类型的符号表示形式。请参阅 ‘Node::type`。

# File prism/node.rb, line 3791
def self.type
  :case_node
end

公共实例方法

===(other) 点击切换源代码

为节点实现 case 等价。这实际上是 ==,但不比较位置的值。位置仅检查是否存在。

# File prism/node.rb, line 3797
def ===(other)
  other.is_a?(CaseNode) &&
    (predicate === other.predicate) &&
    (conditions.length == other.conditions.length) &&
    conditions.zip(other.conditions).all? { |left, right| left === right } &&
    (else_clause === other.else_clause) &&
    (case_keyword_loc.nil? == other.case_keyword_loc.nil?) &&
    (end_keyword_loc.nil? == other.end_keyword_loc.nil?)
end
accept(visitor) 点击切换源代码

def accept: (Visitor visitor) -> void

# File prism/node.rb, line 3684
def accept(visitor)
  visitor.visit_case_node(self)
end
case_keyword() 点击切换源代码

def case_keyword: () -> String

# File prism/node.rb, line 3771
def case_keyword
  case_keyword_loc.slice
end
case_keyword_loc() 点击切换源代码

表示 ‘case` 关键字的位置。

case true; when false; end
^^^^
# File prism/node.rb, line 3742
def case_keyword_loc
  location = @case_keyword_loc
  return location if location.is_a?(Location)
  @case_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end
child_nodes() 点击切换源代码

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

# File prism/node.rb, line 3689
def child_nodes
  [predicate, *conditions, else_clause]
end
也别名为:deconstruct
comment_targets() 点击切换源代码

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

# File prism/node.rb, line 3703
def comment_targets
  [*predicate, *conditions, *else_clause, case_keyword_loc, end_keyword_loc] #: Array[Prism::node | Location]
end
compact_child_nodes() 点击切换源代码

def compact_child_nodes: () -> Array

# File prism/node.rb, line 3694
def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact << predicate if predicate
  compact.concat(conditions)
  compact << else_clause if else_clause
  compact
end
consequent() 点击切换源代码

返回 case 节点的 else 子句。此方法已弃用,建议使用 else_clause

# File prism/node_ext.rb, line 476
def consequent
  deprecated("else_clause")
  else_clause
end
copy(node_id: self.node_id, location: self.location, flags: self.flags, predicate: self.predicate, conditions: self.conditions, else_clause: self.else_clause, case_keyword_loc: self.case_keyword_loc, end_keyword_loc: self.end_keyword_loc) 点击切换源代码

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?predicate: Prism::node?, ?conditions: Array, ?else_clause: ElseNode?, ?case_keyword_loc: Location, ?end_keyword_loc: Location) -> CaseNode

# File prism/node.rb, line 3708
def copy(node_id: self.node_id, location: self.location, flags: self.flags, predicate: self.predicate, conditions: self.conditions, else_clause: self.else_clause, case_keyword_loc: self.case_keyword_loc, end_keyword_loc: self.end_keyword_loc)
  CaseNode.new(source, node_id, location, flags, predicate, conditions, else_clause, case_keyword_loc, end_keyword_loc)
end
deconstruct()

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

别名为:child_nodes
deconstruct_keys(keys) 点击切换源代码

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, predicate: Prism::node?, conditions: Array, else_clause: ElseNode?, case_keyword_loc: Location, end_keyword_loc: Location }

# File prism/node.rb, line 3716
def deconstruct_keys(keys)
  { node_id: node_id, location: location, predicate: predicate, conditions: conditions, else_clause: else_clause, case_keyword_loc: case_keyword_loc, end_keyword_loc: end_keyword_loc }
end
end_keyword() 点击切换源代码

def end_keyword: () -> String

# File prism/node.rb, line 3776
def end_keyword
  end_keyword_loc.slice
end
end_keyword_loc() 点击切换源代码

表示 ‘end` 关键字的位置。

case true; when false; end
                       ^^^
# File prism/node.rb, line 3758
def end_keyword_loc
  location = @end_keyword_loc
  return location if location.is_a?(Location)
  @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end
inspect() 点击切换源代码

def inspect -> String

# File prism/node.rb, line 3781
def inspect
  InspectVisitor.compose(self)
end
save_case_keyword_loc(repository) 点击切换源代码

使用给定的已保存源保存 case_keyword_loc 位置,以便稍后检索。

# File prism/node.rb, line 3750
def save_case_keyword_loc(repository)
  repository.enter(node_id, :case_keyword_loc)
end
save_end_keyword_loc(repository) 点击切换源代码

使用给定的已保存源保存 end_keyword_loc 位置,以便稍后检索。

# File prism/node.rb, line 3766
def save_end_keyword_loc(repository)
  repository.enter(node_id, :end_keyword_loc)
end
type() 点击切换源代码

返回此节点类型的符号表示形式。请参阅 ‘Node#type`。

# File prism/node.rb, line 3786
def type
  :case_node
end