Class: YARP::ModuleNode
- Inherits:
-
YARPNode
- Object
- YARPNode
- YARP::ModuleNode
- Defined in:
- lib/yarp/node.rb,
ext/yarp/api_node.c
Overview
Represents a module declaration involving the ‘module` keyword.
module Foo end
^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
attr_reader body: Node?.
-
#constant_path ⇒ Object
readonly
attr_reader constant_path: Node.
-
#end_keyword_loc ⇒ Object
readonly
attr_reader end_keyword_loc: Location.
-
#locals ⇒ Object
readonly
attr_reader locals: Array.
-
#module_keyword_loc ⇒ Object
readonly
attr_reader module_keyword_loc: Location.
-
#name ⇒ Object
readonly
attr_reader name: Symbol.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#copy(**params) ⇒ Object
def copy: (**params) -> ModuleNode.
- #deconstruct_keys(keys) ⇒ Object
-
#end_keyword ⇒ Object
def end_keyword: () -> String.
-
#initialize(locals, module_keyword_loc, constant_path, body, end_keyword_loc, name, location) ⇒ ModuleNode
constructor
def initialize: (locals: Array, module_keyword_loc: Location, constant_path: Node, body: Node?, end_keyword_loc: Location, name: Symbol, location: Location) -> void.
- #inspect(inspector = NodeInspector.new) ⇒ Object
-
#module_keyword ⇒ Object
def module_keyword: () -> String.
Constructor Details
#initialize(locals, module_keyword_loc, constant_path, body, end_keyword_loc, name, location) ⇒ ModuleNode
def initialize: (locals: Array, module_keyword_loc: Location, constant_path: Node, body: Node?, end_keyword_loc: Location, name: Symbol, location: Location) -> void
7107 7108 7109 7110 7111 7112 7113 7114 7115 |
# File 'lib/yarp/node.rb', line 7107 def initialize(locals, module_keyword_loc, constant_path, body, end_keyword_loc, name, location) @locals = locals @module_keyword_loc = module_keyword_loc @constant_path = constant_path @body = body @end_keyword_loc = end_keyword_loc @name = name @location = location end |
Instance Attribute Details
#body ⇒ Object (readonly)
attr_reader body: Node?
7098 7099 7100 |
# File 'lib/yarp/node.rb', line 7098 def body @body end |
#constant_path ⇒ Object (readonly)
attr_reader constant_path: Node
7095 7096 7097 |
# File 'lib/yarp/node.rb', line 7095 def constant_path @constant_path end |
#end_keyword_loc ⇒ Object (readonly)
attr_reader end_keyword_loc: Location
7101 7102 7103 |
# File 'lib/yarp/node.rb', line 7101 def end_keyword_loc @end_keyword_loc end |
#locals ⇒ Object (readonly)
attr_reader locals: Array
7089 7090 7091 |
# File 'lib/yarp/node.rb', line 7089 def locals @locals end |
#module_keyword_loc ⇒ Object (readonly)
attr_reader module_keyword_loc: Location
7092 7093 7094 |
# File 'lib/yarp/node.rb', line 7092 def module_keyword_loc @module_keyword_loc end |
#name ⇒ Object (readonly)
attr_reader name: Symbol
7104 7105 7106 |
# File 'lib/yarp/node.rb', line 7104 def name @name end |
Instance Method Details
#accept(visitor) ⇒ Object
def accept: (visitor: Visitor) -> void
7118 7119 7120 |
# File 'lib/yarp/node.rb', line 7118 def accept(visitor) visitor.visit_module_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
7123 7124 7125 |
# File 'lib/yarp/node.rb', line 7123 def child_nodes [constant_path, body] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
7128 7129 7130 |
# File 'lib/yarp/node.rb', line 7128 def comment_targets [module_keyword_loc, constant_path, *body, end_keyword_loc] end |
#copy(**params) ⇒ Object
def copy: (**params) -> ModuleNode
7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 |
# File 'lib/yarp/node.rb', line 7133 def copy(**params) ModuleNode.new( params.fetch(:locals) { locals }, params.fetch(:module_keyword_loc) { module_keyword_loc }, params.fetch(:constant_path) { constant_path }, params.fetch(:body) { body }, params.fetch(:end_keyword_loc) { end_keyword_loc }, params.fetch(:name) { name }, params.fetch(:location) { location }, ) end |
#deconstruct_keys(keys) ⇒ Object
7149 7150 7151 |
# File 'lib/yarp/node.rb', line 7149 def deconstruct_keys(keys) { locals: locals, module_keyword_loc: module_keyword_loc, constant_path: constant_path, body: body, end_keyword_loc: end_keyword_loc, name: name, location: location } end |
#end_keyword ⇒ Object
def end_keyword: () -> String
7159 7160 7161 |
# File 'lib/yarp/node.rb', line 7159 def end_keyword end_keyword_loc.slice end |
#inspect(inspector = NodeInspector.new) ⇒ Object
7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 |
# File 'lib/yarp/node.rb', line 7163 def inspect(inspector = NodeInspector.new) inspector << inspector.header(self) inspector << "├── locals: #{locals.inspect}\n" inspector << "├── module_keyword_loc: #{inspector.location(module_keyword_loc)}\n" inspector << "├── constant_path:\n" inspector << inspector.child_node(constant_path, "│ ") if (body = self.body).nil? inspector << "├── body: ∅\n" else inspector << "├── body:\n" inspector << body.inspect(inspector.child_inspector("│ ")).delete_prefix(inspector.prefix) end inspector << "├── end_keyword_loc: #{inspector.location(end_keyword_loc)}\n" inspector << "└── name: #{name.inspect}\n" inspector.to_str end |
#module_keyword ⇒ Object
def module_keyword: () -> String
7154 7155 7156 |
# File 'lib/yarp/node.rb', line 7154 def module_keyword module_keyword_loc.slice end |