Class: YARP::ModuleNode

Inherits:
YARPNode
  • Object
show all
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

Instance Method Summary collapse

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: String, location: Location) -> void



5324
5325
5326
5327
5328
5329
5330
5331
5332
# File 'lib/yarp/node.rb', line 5324

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

#bodyObject (readonly)

attr_reader body: Node?



5315
5316
5317
# File 'lib/yarp/node.rb', line 5315

def body
  @body
end

#constant_pathObject (readonly)

attr_reader constant_path: Node



5312
5313
5314
# File 'lib/yarp/node.rb', line 5312

def constant_path
  @constant_path
end

#end_keyword_locObject (readonly)

attr_reader end_keyword_loc: Location



5318
5319
5320
# File 'lib/yarp/node.rb', line 5318

def end_keyword_loc
  @end_keyword_loc
end

#localsObject (readonly)

attr_reader locals: Array



5306
5307
5308
# File 'lib/yarp/node.rb', line 5306

def locals
  @locals
end

#module_keyword_locObject (readonly)

attr_reader module_keyword_loc: Location



5309
5310
5311
# File 'lib/yarp/node.rb', line 5309

def module_keyword_loc
  @module_keyword_loc
end

#nameObject (readonly)

attr_reader name: String



5321
5322
5323
# File 'lib/yarp/node.rb', line 5321

def name
  @name
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



5335
5336
5337
# File 'lib/yarp/node.rb', line 5335

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

#child_nodesObject Also known as: deconstruct

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



5340
5341
5342
# File 'lib/yarp/node.rb', line 5340

def child_nodes
  [constant_path, body]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ModuleNode



5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
# File 'lib/yarp/node.rb', line 5345

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

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



5361
5362
5363
# File 'lib/yarp/node.rb', line 5361

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_keywordObject

def end_keyword: () -> String



5371
5372
5373
# File 'lib/yarp/node.rb', line 5371

def end_keyword
  end_keyword_loc.slice
end

#module_keywordObject

def module_keyword: () -> String



5366
5367
5368
# File 'lib/yarp/node.rb', line 5366

def module_keyword
  module_keyword_loc.slice
end