Spec-Zone.ru › Ruby 3.4

class Prism::ClassNode

Parent:
Prism::Node

Представляет объявление класса, использующее ключевое слово ‘class`.

class Foo end
^^^^^^^^^^^^^

Атрибуты

body [R]

attr_reader body: StatementsNode | BeginNode | nil

constant_path [R]

attr_reader constant_path: ConstantReadNode | ConstantPathNode | CallNode

locals [R]

attr_reader locals: Массив

name [R]

attr_reader name: Symbol

superclass [R]

attr_reader superclass: Prism::node?

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

new (source, node_id, location, flags, locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, body, end_keyword_loc, name)
Исходный код
# File lib/prism/node.rb, line 3814
def initialize(source, node_id, location, flags, locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, body, end_keyword_loc, name)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @locals = locals
  @class_keyword_loc = class_keyword_loc
  @constant_path = constant_path
  @inheritance_operator_loc = inheritance_operator_loc
  @superclass = superclass
  @body = body
  @end_keyword_loc = end_keyword_loc
  @name = name
end

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

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

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

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

=== (other)
Исходный код
# File lib/prism/node.rb, line 3958
def ===(other)
  other.is_a?(ClassNode) &&
    (locals.length == other.locals.length) &&
    locals.zip(other.locals).all? { |left, right| left === right } &&
    (class_keyword_loc.nil? == other.class_keyword_loc.nil?) &&
    (constant_path === other.constant_path) &&
    (inheritance_operator_loc.nil? == other.inheritance_operator_loc.nil?) &&
    (superclass === other.superclass) &&
    (body === other.body) &&
    (end_keyword_loc.nil? == other.end_keyword_loc.nil?) &&
    (name === other.name)
end

Реализует равенство без учёта регистра для узла. Это фактически ==, но без сравнения значений местоположений. Местоположения проверяются только на наличие.

accept (visitor)
Исходный код
# File lib/prism/node.rb, line 3830
def accept(visitor)
  visitor.visit_class_node(self)
end

def accept: (Visitor visitor) -> void

child_nodes ()
Исходный код
# File lib/prism/node.rb, line 3835
def child_nodes
  [constant_path, superclass, body]
end

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

Также известен как: deconstruct
class_keyword ()
Исходный код
# File lib/prism/node.rb, line 3927
def class_keyword
  class_keyword_loc.slice
end

def class_keyword: () -> String

class_keyword_loc ()
Исходный код
# File lib/prism/node.rb, line 3870
def class_keyword_loc
  location = @class_keyword_loc
  return location if location.is_a?(Location)
  @class_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

attr_reader class_keyword_loc: Location

comment_targets ()
Исходный код
# File lib/prism/node.rb, line 3849
def comment_targets
  [class_keyword_loc, constant_path, *inheritance_operator_loc, *superclass, *body, end_keyword_loc] #: Array[Prism::node | Location]
end

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

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

def compact_child_nodes: () -> Array

copy (node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, class_keyword_loc: self.class_keyword_loc, constant_path: self.constant_path, inheritance_operator_loc: self.inheritance_operator_loc, superclass: self.superclass, body: self.body, end_keyword_loc: self.end_keyword_loc, name: self.name)
Исходный код
# File lib/prism/node.rb, line 3854
def copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, class_keyword_loc: self.class_keyword_loc, constant_path: self.constant_path, inheritance_operator_loc: self.inheritance_operator_loc, superclass: self.superclass, body: self.body, end_keyword_loc: self.end_keyword_loc, name: self.name)
  ClassNode.new(source, node_id, location, flags, locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, body, end_keyword_loc, name)
end

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?class_keyword_loc: Location, ?constant_path: ConstantReadNode | ConstantPathNode | CallNode, ?inheritance_operator_loc: Location?, ?superclass: Prism::node?, ?body: StatementsNode | BeginNode | nil, ?end_keyword_loc: Location, ?name: Symbol) -> ClassNode

deconstruct ()

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

Псевдоним для: child_nodes
deconstruct_keys (keys)
Исходный код
# File lib/prism/node.rb, line 3862
def deconstruct_keys(keys)
  { node_id: node_id, location: location, locals: locals, class_keyword_loc: class_keyword_loc, constant_path: constant_path, inheritance_operator_loc: inheritance_operator_loc, superclass: superclass, body: body, end_keyword_loc: end_keyword_loc, name: name }
end

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, locals: Array, class_keyword_loc: Location, constant_path: ConstantReadNode | ConstantPathNode | CallNode, inheritance_operator_loc: Location?, superclass: Prism::node?, body: StatementsNode | BeginNode | nil, end_keyword_loc: Location, name: Symbol }

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

def end_keyword: () -> String

end_keyword_loc ()
Исходный код
# File lib/prism/node.rb, line 3911
def end_keyword_loc
  location = @end_keyword_loc
  return location if location.is_a?(Location)
  @end_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

attr_reader end_keyword_loc: Location

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

def inheritance_operator: () -> String?

inheritance_operator_loc ()
Исходный код
# File lib/prism/node.rb, line 3886
def inheritance_operator_loc
  location = @inheritance_operator_loc
  case location
  when nil
    nil
  when Location
    location
  else
    @inheritance_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
  end
end

attr_reader inheritance_operator_loc: Location?

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

def inspect -> String

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

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

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

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

save_inheritance_operator_loc (repository)
Исходный код
# File lib/prism/node.rb, line 3900
def save_inheritance_operator_loc(repository)
  repository.enter(node_id, :inheritance_operator_loc) unless @inheritance_operator_loc.nil?
end

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

type ()
Исходный код
# File lib/prism/node.rb, line 3947
def type
  :class_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