Spec-Zone.ru › Ruby 3.4

класс Prism::WhenNode

Родитель:
Prism::Node

Представляет использование ключевого слова ‘when` в операторе case.

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

Атрибуты

conditions [R]

attr_reader conditions: Массив

statements [R]

attr_reader statements: StatementsNode?

Публичные методы класса

new (source, node_id, location, flags, keyword_loc, conditions, then_keyword_loc, statements)
Исходный код
# File lib/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

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

type ()
Исходный код
# File lib/prism/node.rb, line 17957
def self.type
  :when_node
end

Возвращает символ, представляющий тип этого узла. См. ‘Node::type`.

Публичные методы экземпляра

=== (other)
Исходный код
# File lib/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)
Исходный код
# File lib/prism/node.rb, line 17863
def accept(visitor)
  visitor.visit_when_node(self)
end

def accept: (Visitor visitor) -> void

child_nodes ()
Исходный код
# File lib/prism/node.rb, line 17868
def child_nodes
  [*conditions, statements]
end

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

Также алиас: deconstruct
comment_targets ()
Исходный код
# File lib/prism/node.rb, line 17881
def comment_targets
  [keyword_loc, *conditions, *then_keyword_loc, *statements] #: Array[Prism::node | Location]
end

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

compact_child_nodes ()
Исходный код
# File lib/prism/node.rb, line 17873
def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact.concat(conditions)
  compact << statements if statements
  compact
end

def compact_child_nodes: () -> Array

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)
Исходный код
# File lib/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

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?conditions: Массив, ?then_keyword_loc: Location?, ?statements: StatementsNode?) -> WhenNode

deconstruct ()

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

Псевдоним для: child_nodes
deconstruct_keys (keys)
Исходный код
# File lib/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

def deconstruct_keys: (Массив keys) -> { node_id: Integer, location: Location, keyword_loc: Location, conditions: Массив, then_keyword_loc: Location?, statements: StatementsNode? }

inspect ()
Исходный код
# File lib/prism/node.rb, line 17947
def inspect
  InspectVisitor.compose(self)
end

def inspect -> String

keyword ()
Исходный код
# File lib/prism/node.rb, line 17937
def keyword
  keyword_loc.slice
end

def keyword: () -> String

keyword_loc ()
Исходный код
# File lib/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

attr_reader keyword_loc: Location

save_keyword_loc (repository)
Исходный код
# File lib/prism/node.rb, line 17907
def save_keyword_loc(repository)
  repository.enter(node_id, :keyword_loc)
end

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

save_then_keyword_loc (repository)
Исходный код
# File lib/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_loc с помощью предоставленного сохраненного источника, чтобы его можно было получить позже.

then_keyword ()
Исходный код
# File lib/prism/node.rb, line 17942
def then_keyword
  then_keyword_loc&.slice
end

def then_keyword: () -> String?

then_keyword_loc ()
Исходный код
# File lib/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

attr_reader then_keyword_loc: Location?

type ()
Исходный код
# File lib/prism/node.rb, line 17952
def type
  :when_node
end

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

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

Spec-Zone.ru

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