Class: Prism::ModuleNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
ext/prism/api_node.c

Overview

Represents a module declaration involving the ‘module` keyword.

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, locals, module_keyword_loc, constant_path, body, end_keyword_loc, name) ⇒ ModuleNode

Initialize a new ModuleNode node.



11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
# File 'lib/prism/node.rb', line 11585

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

Instance Attribute Details

#bodyObject (readonly)

attr_reader body: StatementsNode | BeginNode | nil



11648
11649
11650
# File 'lib/prism/node.rb', line 11648

def body
  @body
end

#constant_pathObject (readonly)

attr_reader constant_path: ConstantReadNode | ConstantPathNode | MissingNode



11645
11646
11647
# File 'lib/prism/node.rb', line 11645

def constant_path
  @constant_path
end

#localsObject (readonly)

attr_reader locals: Array



11635
11636
11637
# File 'lib/prism/node.rb', line 11635

def locals
  @locals
end

#nameObject (readonly)

attr_reader name: Symbol



11658
11659
11660
# File 'lib/prism/node.rb', line 11658

def name
  @name
end

Class Method Details

.typeObject

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



11681
11682
11683
# File 'lib/prism/node.rb', line 11681

def self.type
  :module_node
end

Instance Method Details

#===(other) ⇒ Object

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



11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
# File 'lib/prism/node.rb', line 11687

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) ⇒ Object

def accept: (Visitor visitor) -> void



11599
11600
11601
# File 'lib/prism/node.rb', line 11599

def accept(visitor)
  visitor.visit_module_node(self)
end

#child_nodesObject Also known as: deconstruct

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



11604
11605
11606
# File 'lib/prism/node.rb', line 11604

def child_nodes
  [constant_path, body]
end

#comment_targetsObject

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



11617
11618
11619
# File 'lib/prism/node.rb', line 11617

def comment_targets
  [module_keyword_loc, constant_path, *body, end_keyword_loc] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



11609
11610
11611
11612
11613
11614
# File 'lib/prism/node.rb', line 11609

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) ⇒ Object

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



11622
11623
11624
# File 'lib/prism/node.rb', line 11622

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_keys(keys) ⇒ Object

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 }



11630
11631
11632
# File 'lib/prism/node.rb', line 11630

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_keywordObject

def end_keyword: () -> String



11666
11667
11668
# File 'lib/prism/node.rb', line 11666

def end_keyword
  end_keyword_loc.slice
end

#end_keyword_locObject

attr_reader end_keyword_loc: Location



11651
11652
11653
11654
11655
# File 'lib/prism/node.rb', line 11651

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

#inspectObject

def inspect -> String



11671
11672
11673
# File 'lib/prism/node.rb', line 11671

def inspect
  InspectVisitor.compose(self)
end

#module_keywordObject

def module_keyword: () -> String



11661
11662
11663
# File 'lib/prism/node.rb', line 11661

def module_keyword
  module_keyword_loc.slice
end

#module_keyword_locObject

attr_reader module_keyword_loc: Location



11638
11639
11640
11641
11642
# File 'lib/prism/node.rb', line 11638

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

#typeObject

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



11676
11677
11678
# File 'lib/prism/node.rb', line 11676

def type
  :module_node
end