Class: YARP::SingletonClassNode

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

Overview

Represents a singleton class declaration involving the ‘class` keyword.

class << self end
^^^^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locals, class_keyword_loc, operator_loc, expression, body, end_keyword_loc, location) ⇒ SingletonClassNode

def initialize: (locals: Array, class_keyword_loc: Location, operator_loc: Location, expression: Node, body: Node?, end_keyword_loc: Location, location: Location) -> void



9198
9199
9200
9201
9202
9203
9204
9205
9206
# File 'lib/yarp/node.rb', line 9198

def initialize(locals, class_keyword_loc, operator_loc, expression, body, end_keyword_loc, location)
  @locals = locals
  @class_keyword_loc = class_keyword_loc
  @operator_loc = operator_loc
  @expression = expression
  @body = body
  @end_keyword_loc = end_keyword_loc
  @location = location
end

Instance Attribute Details

#bodyObject (readonly)

attr_reader body: Node?



9192
9193
9194
# File 'lib/yarp/node.rb', line 9192

def body
  @body
end

#class_keyword_locObject (readonly)

attr_reader class_keyword_loc: Location



9183
9184
9185
# File 'lib/yarp/node.rb', line 9183

def class_keyword_loc
  @class_keyword_loc
end

#end_keyword_locObject (readonly)

attr_reader end_keyword_loc: Location



9195
9196
9197
# File 'lib/yarp/node.rb', line 9195

def end_keyword_loc
  @end_keyword_loc
end

#expressionObject (readonly)

attr_reader expression: Node



9189
9190
9191
# File 'lib/yarp/node.rb', line 9189

def expression
  @expression
end

#localsObject (readonly)

attr_reader locals: Array



9180
9181
9182
# File 'lib/yarp/node.rb', line 9180

def locals
  @locals
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



9186
9187
9188
# File 'lib/yarp/node.rb', line 9186

def operator_loc
  @operator_loc
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



9209
9210
9211
# File 'lib/yarp/node.rb', line 9209

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

#child_nodesObject Also known as: deconstruct

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



9214
9215
9216
# File 'lib/yarp/node.rb', line 9214

def child_nodes
  [expression, body]
end

#class_keywordObject

def class_keyword: () -> String



9245
9246
9247
# File 'lib/yarp/node.rb', line 9245

def class_keyword
  class_keyword_loc.slice
end

#comment_targetsObject

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



9219
9220
9221
# File 'lib/yarp/node.rb', line 9219

def comment_targets
  [class_keyword_loc, operator_loc, expression, *body, end_keyword_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> SingletonClassNode



9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
# File 'lib/yarp/node.rb', line 9224

def copy(**params)
  SingletonClassNode.new(
    params.fetch(:locals) { locals },
    params.fetch(:class_keyword_loc) { class_keyword_loc },
    params.fetch(:operator_loc) { operator_loc },
    params.fetch(:expression) { expression },
    params.fetch(:body) { body },
    params.fetch(:end_keyword_loc) { end_keyword_loc },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

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



9240
9241
9242
# File 'lib/yarp/node.rb', line 9240

def deconstruct_keys(keys)
  { locals: locals, class_keyword_loc: class_keyword_loc, operator_loc: operator_loc, expression: expression, body: body, end_keyword_loc: end_keyword_loc, location: location }
end

#end_keywordObject

def end_keyword: () -> String



9255
9256
9257
# File 'lib/yarp/node.rb', line 9255

def end_keyword
  end_keyword_loc.slice
end

#inspect(inspector = NodeInspector.new) ⇒ Object



9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
# File 'lib/yarp/node.rb', line 9259

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "├── locals: #{locals.inspect}\n"
  inspector << "├── class_keyword_loc: #{inspector.location(class_keyword_loc)}\n"
  inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n"
  inspector << "├── expression:\n"
  inspector << inspector.child_node(expression, "")
  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.to_str
end

#operatorObject

def operator: () -> String



9250
9251
9252
# File 'lib/yarp/node.rb', line 9250

def operator
  operator_loc.slice
end