class Prism::ClassNode
Represents a class declaration involving the class keyword.
class Foo end ^^^^^^^^^^^^^
Public Class Methods
Source
# File lib/prism/node.rb, line 5073 def initialize(source, node_id, location, flags, locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, body, end_keyword_loc, name) @source = source @node_id = node_id @location = location @flags = flags @locals = locals @class_keyword_loc = class_keyword_loc @constant_path = constant_path @inheritance_operator_loc = inheritance_operator_loc @superclass = superclass @body = body @end_keyword_loc = end_keyword_loc @name = name end
Initialize a new ClassNode node.
Public Instance Methods
Source
# File lib/prism/node.rb, line 5244 def body @body end
Represents the body of the class.
class Foo foo ^^^
Source
# File lib/prism/node.rb, line 5195 def constant_path @constant_path end
Returns the constant_path attribute.
Source
# File lib/prism/node.rb, line 5166 def locals @locals end
Returns the locals attribute.
Source
# File lib/prism/node.rb, line 5275 def name @name end
The name of the class.
class Foo end # name `:Foo`
Source
# File lib/prism/node.rb, line 5232 def superclass @superclass end
Represents the superclass of the class.
class Foo < Bar
^^^
Locations
Public Instance Methods
Source
# File lib/prism/node.rb, line 5178 def class_keyword_loc location = @class_keyword_loc return location if location.is_a?(Location) @class_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end
Represents the Location of the class keyword.
class Foo end ^^^^^
Source
# File lib/prism/node.rb, line 5256 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
Represents the Location of the end keyword.
class Foo end
^^^
Source
# File lib/prism/node.rb, line 5207 def inheritance_operator_loc location = @inheritance_operator_loc case location when nil nil when Location location else @inheritance_operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end
Represents the Location of the < operator.
class Foo < Bar
^
Node Interface
Public Class Methods
Public Instance Methods
Source
# File lib/prism/node.rb, line 5100 def accept(visitor) visitor.visit_class_node(self) end
See Node.accept.
Source
# File lib/prism/node.rb, line 5105 def child_nodes [constant_path, superclass, body] end
See Node.child_nodes.
Source
# File lib/prism/node.rb, line 5128 def comment_targets [class_keyword_loc, constant_path, *inheritance_operator_loc, *superclass, *body, end_keyword_loc] #: Array[Prism::node | Location] end
See Node.comment_targets.
Source
# File lib/prism/node.rb, line 5119 def compact_child_nodes compact = [] #: Array[Prism::node] compact << constant_path compact << superclass if superclass compact << body if body compact end
Source
# File lib/prism/node.rb, line 5136 def copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, class_keyword_loc: self.class_keyword_loc, constant_path: self.constant_path, inheritance_operator_loc: self.inheritance_operator_loc, superclass: self.superclass, body: self.body, end_keyword_loc: self.end_keyword_loc, name: self.name) ClassNode.new(source, node_id, location, flags, locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, body, end_keyword_loc, name) end
Creates a copy of self with the given fields, using self as the template.
Source
# File lib/prism/node.rb, line 5110 def each_child_node return to_enum(:each_child_node) unless block_given? yield constant_path yield superclass if superclass yield body if body end
See Node.each_child_node.
Repository
Public Instance Methods
Source
# File lib/prism/node.rb, line 5187 def save_class_keyword_loc(repository) repository.enter(node_id, :class_keyword_loc) end
Save the class_keyword_loc location using the given saved source so that it can be retrieved later.
Source
# File lib/prism/node.rb, line 5265 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.
Source
# File lib/prism/node.rb, line 5222 def save_inheritance_operator_loc(repository) repository.enter(node_id, :inheritance_operator_loc) unless @inheritance_operator_loc.nil? end
Save the inheritance_operator_loc location using the given saved source so that it can be retrieved later.
Slicing
Public Instance Methods
Source
# File lib/prism/node.rb, line 5285 def class_keyword class_keyword_loc.slice end
Slice the location of class_keyword_loc from the source.
Source
# File lib/prism/node.rb, line 5301 def end_keyword end_keyword_loc.slice end
Slice the location of end_keyword_loc from the source.
Source
# File lib/prism/node.rb, line 5293 def inheritance_operator inheritance_operator_loc&.slice end
Slice the location of inheritance_operator_loc from the source.