class Prism::RescueNode
Представляет оператор rescue.
begin rescue Foo, *splat, Bar => ex foo ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ end
‘Foo, *splat, Bar` находятся в поле `exceptions`. `ex` находится в поле `reference`.
Атрибуты
attr_reader exceptions: Массив
attr_reader reference: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode | null
attr_reader statements: StatementsNode?
attr_reader subsequent: RescueNode?
Открытые методы класса
Исходный код
# File lib/prism/node.rb, line 15712 def initialize(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, statements, subsequent) @source = source @node_id = node_id @location = location @flags = flags @keyword_loc = keyword_loc @exceptions = exceptions @operator_loc = operator_loc @reference = reference @statements = statements @subsequent = subsequent end
Инициализировать новый узел RescueNode.
Исходный код
# File lib/prism/node.rb, line 15828 def self.type :rescue_node end
Возвращает символ, представляющий тип этого узла. См. ‘Node::type`.
Публичные методы экземпляра
Исходный код
# File lib/prism/node.rb, line 15834
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) &&
(statements === other.statements) &&
(subsequent === other.subsequent)
end Реализует равенство по значению для узла. Это фактически ==, но без сравнения значения местоположений. Местоположения проверяются только на наличие.
Исходный код
# File lib/prism/node.rb, line 15726 def accept(visitor) visitor.visit_rescue_node(self) end
def accept: (Visitor visitor) -> void
Исходный код
# File lib/prism/node.rb, line 15731 def child_nodes [*exceptions, reference, statements, subsequent] end
def child_nodes: () -> Array[nil | Node]
Исходный код
# File lib/prism/node.rb, line 15746 def comment_targets [keyword_loc, *exceptions, *operator_loc, *reference, *statements, *subsequent] #: Array[Prism::node | Location] end
def comment_targets: () -> Array[Node | Location]
Исходный код
# File lib/prism/node.rb, line 15736 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
Исходный код
# File lib/prism/node_ext.rb, line 494
def consequent
deprecated("subsequent")
subsequent
end Возвращает последующее предложение rescue узла. Этот метод устарел в пользу subsequent.
Исходный код
# File lib/prism/node.rb, line 15751 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, statements: self.statements, subsequent: self.subsequent) RescueNode.new(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, 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, ?statements: StatementsNode?, ?subsequent: RescueNode?) -> RescueNode
Исходный код
# File lib/prism/node.rb, line 15759
def deconstruct_keys(keys)
{ node_id: node_id, location: location, keyword_loc: keyword_loc, exceptions: exceptions, operator_loc: operator_loc, reference: reference, 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, statements: StatementsNode?, subsequent: RescueNode? }
Исходный код
# File lib/prism/node.rb, line 15818 def inspect InspectVisitor.compose(self) end
def inspect -> String
Исходный код
# File lib/prism/node.rb, line 15808 def keyword keyword_loc.slice end
def keyword: () -> String
Исходный код
# File lib/prism/node.rb, line 15764 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
Исходный код
# File lib/prism/node.rb, line 15813 def operator operator_loc&.slice end
def operator: () -> String?
Исходный код
# File lib/prism/node.rb, line 15780
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?
Исходный код
# File lib/prism/node.rb, line 15772 def save_keyword_loc(repository) repository.enter(node_id, :keyword_loc) end
Сохранить местоположение keyword_loc с помощью предоставленного сохранённого источника, чтобы его можно было извлечь позже.
Исходный код
# File lib/prism/node.rb, line 15794 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) unless @operator_loc.nil? end
Сохранить местоположение operator_loc с помощью предоставленного сохранённого источника, чтобы его можно было извлечь позже.
Исходный код
# File lib/prism/node.rb, line 15823 def type :rescue_node end
Возвращает символьную запись типа этого узла. См. ‘Node#type’.
Ruby Core © 1993–2024 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.