Spec-Zone.ru › Ruby 3.4
  1. Prism::
  2. RescueNode

class Prism::RescueNode

Родительский класс:
Prism::Node

Представляет оператор rescue.

begin
rescue Foo, *splat, Bar => ex
  foo
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
end

Foo, *splat, Bar находятся в поле exceptions. ex находится в поле reference.

Атрибуты

exceptions [R]

attr_reader exceptions: Array

reference [R]

attr_reader reference: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode | nil

statements [R]

attr_reader statements: StatementsNode?

subsequent [R]

attr_reader subsequent: RescueNode?

Открытые методы класса

new (source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, then_keyword_loc, statements, subsequent) Показать исходный код
# File lib/prism/node.rb, line 15889
def initialize(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, then_keyword_loc, statements, subsequent)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @keyword_loc = keyword_loc
  @exceptions = exceptions
  @operator_loc = operator_loc
  @reference = reference
  @then_keyword_loc = then_keyword_loc
  @statements = statements
  @subsequent = subsequent
end

Инициализирует новый узел RescueNode.

type () Показать исходный код
# File lib/prism/node.rb, line 16030
def self.type
  :rescue_node
end

Возвращает символьное представление типа этого узла. См. Node::type.

Открытые методы экземпляра

=== (other) Показать исходный код
# File lib/prism/node.rb, line 16036
def ===(other)
  other.is_a?(RescueNode) &&
    (keyword_loc.nil? == other.keyword_loc.nil?) &&
    (exceptions.length == other.exceptions.length) &&
    exceptions.zip(other.exceptions).all? { |left, right| left === right } &&
    (operator_loc.nil? == other.operator_loc.nil?) &&
    (reference === other.reference) &&
    (then_keyword_loc.nil? == other.then_keyword_loc.nil?) &&
    (statements === other.statements) &&
    (subsequent === other.subsequent)
end

Реализует проверку равенства по типу для узла. По сути, это оператор ==, но без сравнения значений расположений. Проверяется только наличие расположений.

accept (visitor) Показать исходный код
# File lib/prism/node.rb, line 15904
def accept(visitor)
  visitor.visit_rescue_node(self)
end

def accept: (Visitor visitor) -> void

child_nodes () Показать исходный код
# File lib/prism/node.rb, line 15909
def child_nodes
  [*exceptions, reference, statements, subsequent]
end

def child_nodes: () -> Array

Также имеет псевдоним: deconstruct
comment_targets () Показать исходный код
# File lib/prism/node.rb, line 15924
def comment_targets
  [keyword_loc, *exceptions, *operator_loc, *reference, *then_keyword_loc, *statements, *subsequent] #: Array[Prism::node | Location]
end

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

compact_child_nodes () Показать исходный код
# File lib/prism/node.rb, line 15914
def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact.concat(exceptions)
  compact << reference if reference
  compact << statements if statements
  compact << subsequent if subsequent
  compact
end

def compact_child_nodes: () -> Array

consequent () Показать исходный код
# File lib/prism/node_ext.rb, line 497
def consequent
  deprecated("subsequent")
  subsequent
end

Возвращает следующий раздел rescue узла rescue. Этот метод устарел; вместо него следует использовать subsequent.

copy (node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, exceptions: self.exceptions, operator_loc: self.operator_loc, reference: self.reference, then_keyword_loc: self.then_keyword_loc, statements: self.statements, subsequent: self.subsequent) Показать исходный код
# File lib/prism/node.rb, line 15929
def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, exceptions: self.exceptions, operator_loc: self.operator_loc, reference: self.reference, then_keyword_loc: self.then_keyword_loc, statements: self.statements, subsequent: self.subsequent)
  RescueNode.new(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, then_keyword_loc, statements, subsequent)
end

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?exceptions: Array, ?operator_loc: Location?, ?reference: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode | nil, ?then_keyword_loc: Location?, ?statements: StatementsNode?, ?subsequent: RescueNode?) -> RescueNode

deconstruct ()

def deconstruct: () -> Array

Псевдоним для: child_nodes
deconstruct_keys (keys) Показать исходный код
# File lib/prism/node.rb, line 15937
def deconstruct_keys(keys)
  { node_id: node_id, location: location, keyword_loc: keyword_loc, exceptions: exceptions, operator_loc: operator_loc, reference: reference, then_keyword_loc: then_keyword_loc, statements: statements, subsequent: subsequent }
end

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, keyword_loc: Location, exceptions: Array, operator_loc: Location?, reference: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode | nil, then_keyword_loc: Location?, statements: StatementsNode?, subsequent: RescueNode? }

inspect () Показать исходный код
# File lib/prism/node.rb, line 16020
def inspect
  InspectVisitor.compose(self)
end

def inspect -> String

keyword () Показать исходный код
# File lib/prism/node.rb, line 16005
def keyword
  keyword_loc.slice
end

def keyword: () -> String

keyword_loc () Показать исходный код
# File lib/prism/node.rb, line 15942
def keyword_loc
  location = @keyword_loc
  return location if location.is_a?(Location)
  @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

attr_reader keyword_loc: Location

operator () Показать исходный код
# File lib/prism/node.rb, line 16010
def operator
  operator_loc&.slice
end

def operator: () -> String?

operator_loc () Показать исходный код
# File lib/prism/node.rb, line 15958
def operator_loc
  location = @operator_loc
  case location
  when nil
    nil
  when Location
    location
  else
    @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
  end
end

attr_reader operator_loc: Location?

save_keyword_loc (repository) Показать исходный код
# File lib/prism/node.rb, line 15950
def save_keyword_loc(repository)
  repository.enter(node_id, :keyword_loc)
end

Сохраните местоположение keyword_loc с помощью указанного сохранённого исходного кода, чтобы его можно было получить позже.

save_operator_loc (repository) Показать исходный код
# File lib/prism/node.rb, line 15972
def save_operator_loc(repository)
  repository.enter(node_id, :operator_loc) unless @operator_loc.nil?
end

Сохраните местоположение operator_loc с помощью указанного сохранённого исходного кода, чтобы его можно было получить позже.

save_then_keyword_loc (repository) Показать исходный код
# File lib/prism/node.rb, line 15994
def save_then_keyword_loc(repository)
  repository.enter(node_id, :then_keyword_loc) unless @then_keyword_loc.nil?
end

Сохраните местоположение then_keyword_loc с помощью указанного сохранённого исходного кода, чтобы его можно было получить позже.

then_keyword () Показать исходный код
# File lib/prism/node.rb, line 16015
def then_keyword
  then_keyword_loc&.slice
end

def then_keyword: () -> String?

then_keyword_loc () Показать исходный код
# File lib/prism/node.rb, line 15980
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

attr_reader then_keyword_loc: Location?

type () Показать исходный код
# File lib/prism/node.rb, line 16025
def type
  :rescue_node
end

Возвращает символьное представление типа этого узла. См. Node#type.

Ruby Core © 1993–2025 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API