class Prism::ModuleNode

Represents a module declaration involving the module keyword.

module Foo end
^^^^^^^^^^^^^^

Attributes

body[R]

attr_reader body: StatementsNode | BeginNode | nil

constant_path[R]
locals[R]

attr_reader locals: Array

name[R]

attr_reader name: Symbol

Public Class Methods

new(source, node_id, location, flags, locals, module_keyword_loc, constant_path, body, end_keyword_loc, name) click to toggle source

Initialize a new ModuleNode node.

# File lib/prism/node.rb, line 12622
def initialize(source, node_id, location, flags, locals, module_keyword_loc, constant_path, body, end_keyword_loc, name)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @locals = locals
  @module_keyword_loc = module_keyword_loc
  @constant_path = constant_path
  @body = body
  @end_keyword_loc = end_keyword_loc
  @name = name
end
type() click to toggle source

Return a symbol representation of this node type. See Node::type.

# File lib/prism/node.rb, line 12730
def self.type
  :module_node
end

Public Instance Methods

===(other) click to toggle source

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.

# File lib/prism/node.rb, line 12736
def ===(other)
  other.is_a?(ModuleNode) &&
    (locals.length == other.locals.length) &&
    locals.zip(other.locals).all? { |left, right| left === right } &&
    (module_keyword_loc.nil? == other.module_keyword_loc.nil?) &&
    (constant_path === other.constant_path) &&
    (body === other.body) &&
    (end_keyword_loc.nil? == other.end_keyword_loc.nil?) &&
    (name === other.name)
end
accept(visitor) click to toggle source

def accept: (Visitor visitor) -> void

# File lib/prism/node.rb, line 12636
def accept(visitor)
  visitor.visit_module_node(self)
end
child_nodes() click to toggle source

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

# File lib/prism/node.rb, line 12641
def child_nodes
  [constant_path, body]
end
Also aliased as: deconstruct
comment_targets() click to toggle source

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

# File lib/prism/node.rb, line 12654
def comment_targets
  [module_keyword_loc, constant_path, *body, end_keyword_loc] #: Array[Prism::node | Location]
end
compact_child_nodes() click to toggle source

def compact_child_nodes: () -> Array

# File lib/prism/node.rb, line 12646
def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact << constant_path
  compact << body if body
  compact
end
copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, module_keyword_loc: self.module_keyword_loc, constant_path: self.constant_path, body: self.body, end_keyword_loc: self.end_keyword_loc, name: self.name) click to toggle source

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?module_keyword_loc: Location, ?constant_path: ConstantReadNode | ConstantPathNode | MissingNode, ?body: StatementsNode | BeginNode | nil, ?end_keyword_loc: Location, ?name: Symbol) -> ModuleNode

# File lib/prism/node.rb, line 12659
def copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, module_keyword_loc: self.module_keyword_loc, constant_path: self.constant_path, body: self.body, end_keyword_loc: self.end_keyword_loc, name: self.name)
  ModuleNode.new(source, node_id, location, flags, locals, module_keyword_loc, constant_path, body, end_keyword_loc, name)
end
deconstruct()

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

Alias for: child_nodes
deconstruct_keys(keys) click to toggle source

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, locals: Array, module_keyword_loc: Location, constant_path: ConstantReadNode | ConstantPathNode | MissingNode, body: StatementsNode | BeginNode | nil, end_keyword_loc: Location, name: Symbol }

# File lib/prism/node.rb, line 12667
def deconstruct_keys(keys)
  { node_id: node_id, location: location, locals: locals, module_keyword_loc: module_keyword_loc, constant_path: constant_path, body: body, end_keyword_loc: end_keyword_loc, name: name }
end
end_keyword() click to toggle source

def end_keyword: () -> String

# File lib/prism/node.rb, line 12715
def end_keyword
  end_keyword_loc.slice
end
end_keyword_loc() click to toggle source

attr_reader end_keyword_loc: Location

# File lib/prism/node.rb, line 12694
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
inspect() click to toggle source

def inspect -> String

# File lib/prism/node.rb, line 12720
def inspect
  InspectVisitor.compose(self)
end
module_keyword() click to toggle source

def module_keyword: () -> String

# File lib/prism/node.rb, line 12710
def module_keyword
  module_keyword_loc.slice
end
module_keyword_loc() click to toggle source

attr_reader module_keyword_loc: Location

# File lib/prism/node.rb, line 12675
def module_keyword_loc
  location = @module_keyword_loc
  return location if location.is_a?(Location)
  @module_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end
save_end_keyword_loc(repository) click to toggle source

Save the end_keyword_loc location using the given saved source so that it can be retrieved later.

# File lib/prism/node.rb, line 12702
def save_end_keyword_loc(repository)
  repository.enter(node_id, :end_keyword_loc)
end
save_module_keyword_loc(repository) click to toggle source

Save the module_keyword_loc location using the given saved source so that it can be retrieved later.

# File lib/prism/node.rb, line 12683
def save_module_keyword_loc(repository)
  repository.enter(node_id, :module_keyword_loc)
end
type() click to toggle source

Return a symbol representation of this node type. See Node#type.

# File lib/prism/node.rb, line 12725
def type
  :module_node
end