class Prism::ModuleNode - Documentation for Ruby 4.0
Description: class Prism::ModuleNode: Represents a module declaration involving the `module` keyword.
Keywords: ruby,class,Prism::ModuleNode

🔍

No recent searches

# 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]

attr_reader `constant_path`: `ConstantReadNode` | `ConstantPathNode` | `MissingNode`

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)
Source

    # File lib/prism/node.rb, line 13831
    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

Initialize a new `ModuleNode` node.

type ()
Source

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

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

### Public Instance Methods

=== (other)
Source

    # File lib/prism/node.rb, line 13953
    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

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

accept (visitor)
Source

    # File lib/prism/node.rb, line 13845
    def accept(visitor)
      visitor.visit_module_node(self)
    end

def accept: (`Visitor` visitor) -> void

child_nodes ()
Source

    # File lib/prism/node.rb, line 13850
    def child_nodes
      [constant_path, body]
    end

def `child_nodes`: () -> Array

Also aliased as: deconstruct
comment_targets ()
Source

    # File lib/prism/node.rb, line 13871
    def comment_targets
      [module_keyword_loc, constant_path, *body, end_keyword_loc] #: Array[Prism::node | Location]
    end

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

compact_child_nodes ()
Source

    # File lib/prism/node.rb, line 13863
    def compact_child_nodes
      compact = [] #: Array[Prism::node]
      compact << constant_path
      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, 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)
Source

    # File lib/prism/node.rb, line 13876
    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

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`

deconstruct ()

def deconstruct: () -> Array

Alias for: child_nodes
deconstruct_keys (keys)
Source

    # File lib/prism/node.rb, line 13884
    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

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` }

each_child_node () { |constant_path| ... }
Source

    # File lib/prism/node.rb, line 13855
    def each_child_node
      return to_enum(:each_child_node) unless block_given?

      yield constant_path
      yield body if body
    end

def `each_child_node`: () { (Prism::node) -> void } -> void | () -> Enumerator

end_keyword ()
Source

    # File lib/prism/node.rb, line 13932
    def end_keyword
      end_keyword_loc.slice
    end

def `end_keyword`: () -> `String`

end_keyword_loc ()
Source

    # File lib/prism/node.rb, line 13911
    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`

inspect ()
Source

    # File lib/prism/node.rb, line 13937
    def inspect
      InspectVisitor.compose(self)
    end

def inspect -> `String`

module_keyword ()
Source

    # File lib/prism/node.rb, line 13927
    def module_keyword
      module_keyword_loc.slice
    end

def `module_keyword`: () -> `String`

module_keyword_loc ()
Source

    # File lib/prism/node.rb, line 13892
    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

attr_reader `module_keyword_loc`: `Location`

save_end_keyword_loc (repository)
Source

    # File lib/prism/node.rb, line 13919
    def save_end_keyword_loc(repository)
      repository.enter(node_id, :end_keyword_loc)
    end

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

save_module_keyword_loc (repository)
Source

    # File lib/prism/node.rb, line 13900
    def save_module_keyword_loc(repository)
      repository.enter(node_id, :module_keyword_loc)
    end

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

type ()
Source

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

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