Spec-Zone.ru › Ruby 3.3

класс Prism::EmbeddedVariableNode

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

Представляет интерполированную переменную.

"foo #@bar"
     ^^^^^

Атрибуты

operator_loc[R]

attr_reader operator_loc: Location

variable[R]

attr_reader variable: Node

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

new(operator_loc, variable, location) Показать исходный код
# File lib/prism/node.rb, line 5802
def initialize(operator_loc, variable, location)
  @operator_loc = operator_loc
  @variable = variable
  @location = location
end

def initialize: (operator_loc: Location, variable: Node, location: Location) -> void

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

Аналогично type, этот метод возвращает символ, который можно использовать для разделения по типу узла, без необходимости выполнения длинной цепочки ===. Обратите внимание, что, как и type, он по-прежнему будет медленнее, чем использование == для одного класса, но должен быть быстрее в операторе case или сравнении массивов.

def self.type: () -> Symbol

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

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

def accept: (visitor: Visitor) -> void

child_nodes() Показать исходный код
# File lib/prism/node.rb, line 5814
def child_nodes
  [variable]
end

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

Также алиас: deconstruct
comment_targets() Показать исходный код
# File lib/prism/node.rb, line 5824
def comment_targets
  [operator_loc, variable]
end

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

compact_child_nodes() Показать исходный код
# File lib/prism/node.rb, line 5819
def compact_child_nodes
  [variable]
end

def compact_child_nodes: () -> Массив

copy(**params) Показать исходный код
# File lib/prism/node.rb, line 5829
def copy(**params)
  EmbeddedVariableNode.new(
    params.fetch(:operator_loc) { operator_loc },
    params.fetch(:variable) { variable },
    params.fetch(:location) { location },
  )
end

def copy: (**params) -> EmbeddedVariableNode

deconstruct()

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

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

def deconstruct_keys: (keys: Массив) -> Словарь[Символ, nil | Node | Массив | String | Token | Массив | Location]

inspect(inspector = NodeInspector.new) Показать исходный код
# File lib/prism/node.rb, line 5851
def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n"
  inspector << "└── variable:\n"
  inspector << inspector.child_node(variable, "    ")
  inspector.to_str
end

def inspect(inspector: NodeInspector) -> String

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

def operator: () -> String

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

Иногда требуется проверить экземпляр узла по списку классов, чтобы определить, какое поведение следует выполнить. Обычно это делается с помощью вызова `[cls1, cls2].include?(node.class)` или размещения узла в операторе case и выполнения `case node; when cls1; when cls2; end`. Оба этих подхода относительно медленные из-за постоянных обращений, вызовов методов и/или выделения массивов.

Вместо этого можно вызвать type, который вернёт символ, который можно использовать для сравнения. Это быстрее, чем другие подходы, потому что используется одно целочисленное сравнение, а также, если вы используете CRuby, можно воспользоваться тем, что операторы case со всеми символами ключей будут использовать таблицу переходов.

def type: () -> Symbol

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

Spec-Zone.ru

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