class Prism::ModuleNode - Documentation for Ruby 4.1
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
    ^^^^^^^^^^^^^^

### 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 21980
    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.

### Public Instance Methods

body → StatementsNode | BeginNode | nil
Source

    # File lib/prism/node.rb, line 22132
    def body
      @body
    end

Returns the `body` attribute.

constant_path → ConstantReadNode | ConstantPathNode
Source

    # File lib/prism/node.rb, line 22122
    def constant_path
      @constant_path
    end

Returns the `constant_path` attribute.

locals → Array[Symbol]
Source

    # File lib/prism/node.rb, line 22090
    def locals
      @locals
    end

Returns the `locals` attribute.

name → Symbol
Source

    # File lib/prism/node.rb, line 22164
    def name
      @name
    end

Returns the `name` attribute.

## Locations

### Public Instance Methods

end_keyword_loc → Location
Source

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

Returns the `Location` represented by `end_keyword_loc`.

module_keyword_loc → Location
Source

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

Returns the `Location` represented by `module_keyword_loc`.

## Node Interface

These methods are present on all subclasses of `Node`. Read the node interface docs for more information.

### Public Class Methods

type ()
Source

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

See `Node.type`.

### Public Instance Methods

accept (visitor)
Source

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

See `Node.accept`.

child_nodes ()
Source

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

See `Node.child_nodes`.

Also aliased as: deconstruct
comment_targets ()
Source

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

See `Node.comment_targets`.

compact_child_nodes ()
Source

    # File lib/prism/node.rb, line 22032
    def compact_child_nodes
      compact = [] #: Array[Prism::node]
      compact << constant_path
      if (body = self.body); compact << body; end
      compact
    end

See `Node.compact_child_nodes`.

copy(**fields) → ModuleNode
Source

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

Creates a copy of self with the given fields, using self as the template.

deconstruct ()
Alias for: child_nodes
each_child_node () { |constant_path| ... }
Source

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

      yield constant_path
      if (body = self.body); yield body; end
    end

See `Node.each_child_node`.

type ()
Source

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

See `Node#type`.

## Repository

Methods related to `Relocation`.

### Public Instance Methods

save_end_keyword_loc (repository)
Source

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

## Slicing

### Public Instance Methods

end_keyword → String
Source

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

Slice the location of `end_keyword_loc` from the source.

module_keyword → String
Source

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

Slice the location of `module_keyword_loc` from the source.