class Prism::WhenNode

表示 case 语句中 `when` 关键字的使用。

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

属性

conditions[R]

attr_reader conditions: Array

statements[R]

attr_reader statements: StatementsNode?

公共类方法

new(source, node_id, location, flags, keyword_loc, conditions, then_keyword_loc, statements) 点击切换源码

初始化一个新的 WhenNode 节点。

# File prism/node.rb, line 17851
def initialize(source, node_id, location, flags, keyword_loc, conditions, then_keyword_loc, statements)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @keyword_loc = keyword_loc
  @conditions = conditions
  @then_keyword_loc = then_keyword_loc
  @statements = statements
end
type() 点击切换源码

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

# File prism/node.rb, line 17957
def self.type
  :when_node
end

公共实例方法

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

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

# File prism/node.rb, line 17963
def ===(other)
  other.is_a?(WhenNode) &&
    (keyword_loc.nil? == other.keyword_loc.nil?) &&
    (conditions.length == other.conditions.length) &&
    conditions.zip(other.conditions).all? { |left, right| left === right } &&
    (then_keyword_loc.nil? == other.then_keyword_loc.nil?) &&
    (statements === other.statements)
end
accept(visitor) 点击切换源码

def accept: (Visitor visitor) -> void

# File prism/node.rb, line 17863
def accept(visitor)
  visitor.visit_when_node(self)
end
child_nodes() 点击切换源码

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

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

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

# File prism/node.rb, line 17881
def comment_targets
  [keyword_loc, *conditions, *then_keyword_loc, *statements] #: Array[Prism::node | Location]
end
compact_child_nodes() 点击切换源码

def compact_child_nodes: () -> Array

# File prism/node.rb, line 17873
def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact.concat(conditions)
  compact << statements if statements
  compact
end
copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, conditions: self.conditions, then_keyword_loc: self.then_keyword_loc, statements: self.statements) 点击切换源码

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?conditions: Array, ?then_keyword_loc: Location?, ?statements: StatementsNode?) -> WhenNode

# File prism/node.rb, line 17886
def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, conditions: self.conditions, then_keyword_loc: self.then_keyword_loc, statements: self.statements)
  WhenNode.new(source, node_id, location, flags, keyword_loc, conditions, then_keyword_loc, statements)
end
deconstruct()

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

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

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, keyword_loc: Location, conditions: Array, then_keyword_loc: Location?, statements: StatementsNode? }

# File prism/node.rb, line 17894
def deconstruct_keys(keys)
  { node_id: node_id, location: location, keyword_loc: keyword_loc, conditions: conditions, then_keyword_loc: then_keyword_loc, statements: statements }
end
inspect() 点击切换源码

def inspect -> String

# File prism/node.rb, line 17947
def inspect
  InspectVisitor.compose(self)
end
keyword() 点击切换源码

def keyword: () -> String

# File prism/node.rb, line 17937
def keyword
  keyword_loc.slice
end
keyword_loc() 点击切换源码

attr_reader keyword_loc: Location

# File prism/node.rb, line 17899
def keyword_loc
  location = @keyword_loc
  return location if location.is_a?(Location)
  @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end
save_keyword_loc(repository) 点击切换源码

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

# File prism/node.rb, line 17907
def save_keyword_loc(repository)
  repository.enter(node_id, :keyword_loc)
end
save_then_keyword_loc(repository) 点击切换源码

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

# File prism/node.rb, line 17929
def save_then_keyword_loc(repository)
  repository.enter(node_id, :then_keyword_loc) unless @then_keyword_loc.nil?
end
then_keyword() 点击切换源码

def then_keyword: () -> String?

# File prism/node.rb, line 17942
def then_keyword
  then_keyword_loc&.slice
end
then_keyword_loc() 点击切换源码

attr_reader then_keyword_loc: Location?

# File prism/node.rb, line 17915
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
type() 点击切换源码

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

# File prism/node.rb, line 17952
def type
  :when_node
end