Class: Prism::ClassNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ClassNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents a class declaration involving the ‘class` keyword.
class Foo end
^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Represents the body of the class.
-
#constant_path ⇒ Object
readonly
attr_reader constant_path: ConstantReadNode | ConstantPathNode | CallNode.
-
#locals ⇒ Object
readonly
attr_reader locals: Array.
-
#name ⇒ Object
readonly
The name of the class.
-
#superclass ⇒ Object
readonly
Represents the superclass of the class.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array.
-
#class_keyword ⇒ Object
def class_keyword: () -> String.
-
#class_keyword_loc ⇒ Object
Represents the location of the ‘class` keyword.
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#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) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?class_keyword_loc: Location, ?constant_path: ConstantReadNode | ConstantPathNode | CallNode, ?inheritance_operator_loc: Location?, ?superclass: Prism::node?, ?body: StatementsNode | BeginNode | nil, ?end_keyword_loc: Location, ?name: Symbol) -> ClassNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, locals: Array, class_keyword_loc: Location, constant_path: ConstantReadNode | ConstantPathNode | CallNode, inheritance_operator_loc: Location?, superclass: Prism::node?, body: StatementsNode | BeginNode | nil, end_keyword_loc: Location, name: Symbol }.
-
#end_keyword ⇒ Object
def end_keyword: () -> String.
-
#end_keyword_loc ⇒ Object
Represents the location of the ‘end` keyword.
-
#inheritance_operator ⇒ Object
def inheritance_operator: () -> String?.
-
#inheritance_operator_loc ⇒ Object
Represents the location of the ‘<` operator.
-
#initialize(source, node_id, location, flags, locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, body, end_keyword_loc, name) ⇒ ClassNode
constructor
Initialize a new ClassNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#save_class_keyword_loc(repository) ⇒ Object
Save the class_keyword_loc location using the given saved source so that it can be retrieved later.
-
#save_end_keyword_loc(repository) ⇒ Object
Save the end_keyword_loc location using the given saved source so that it can be retrieved later.
-
#save_inheritance_operator_loc(repository) ⇒ Object
Save the inheritance_operator_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, locals, class_keyword_loc, constant_path, inheritance_operator_loc, superclass, body, end_keyword_loc, name) ⇒ ClassNode
Initialize a new ClassNode node.
3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 |
# File 'lib/prism/node.rb', line 3826 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 |
Instance Attribute Details
#body ⇒ Object (readonly)
Represents the body of the class.
class Foo
foo
^^^
3933 3934 3935 |
# File 'lib/prism/node.rb', line 3933 def body @body end |
#constant_path ⇒ Object (readonly)
attr_reader constant_path: ConstantReadNode | ConstantPathNode | CallNode
3898 3899 3900 |
# File 'lib/prism/node.rb', line 3898 def constant_path @constant_path end |
#locals ⇒ Object (readonly)
attr_reader locals: Array
3879 3880 3881 |
# File 'lib/prism/node.rb', line 3879 def locals @locals end |
#name ⇒ Object (readonly)
The name of the class.
class Foo end # name `:Foo`
3954 3955 3956 |
# File 'lib/prism/node.rb', line 3954 def name @name end |
#superclass ⇒ Object (readonly)
Represents the superclass of the class.
class Foo < Bar
^^^
3926 3927 3928 |
# File 'lib/prism/node.rb', line 3926 def superclass @superclass end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
3982 3983 3984 |
# File 'lib/prism/node.rb', line 3982 def self.type :class_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.
3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 |
# File 'lib/prism/node.rb', line 3988 def ===(other) other.is_a?(ClassNode) && (locals.length == other.locals.length) && locals.zip(other.locals).all? { |left, right| left === right } && (class_keyword_loc.nil? == other.class_keyword_loc.nil?) && (constant_path === other.constant_path) && (inheritance_operator_loc.nil? == other.inheritance_operator_loc.nil?) && (superclass === other.superclass) && (body === other.body) && (end_keyword_loc.nil? == other.end_keyword_loc.nil?) && (name === other.name) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
3842 3843 3844 |
# File 'lib/prism/node.rb', line 3842 def accept(visitor) visitor.visit_class_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
3847 3848 3849 |
# File 'lib/prism/node.rb', line 3847 def child_nodes [constant_path, superclass, body] end |
#class_keyword ⇒ Object
def class_keyword: () -> String
3957 3958 3959 |
# File 'lib/prism/node.rb', line 3957 def class_keyword class_keyword_loc.slice end |
#class_keyword_loc ⇒ Object
Represents the location of the ‘class` keyword.
class Foo end
^^^^^
3885 3886 3887 3888 3889 |
# File 'lib/prism/node.rb', line 3885 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 |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
3861 3862 3863 |
# File 'lib/prism/node.rb', line 3861 def comment_targets [class_keyword_loc, constant_path, *inheritance_operator_loc, *superclass, *body, end_keyword_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
3852 3853 3854 3855 3856 3857 3858 |
# File 'lib/prism/node.rb', line 3852 def compact_child_nodes compact = [] #: Array[Prism::node] compact << constant_path compact << superclass if superclass compact << body if body compact end |
#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) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?class_keyword_loc: Location, ?constant_path: ConstantReadNode | ConstantPathNode | CallNode, ?inheritance_operator_loc: Location?, ?superclass: Prism::node?, ?body: StatementsNode | BeginNode | nil, ?end_keyword_loc: Location, ?name: Symbol) -> ClassNode
3866 3867 3868 |
# File 'lib/prism/node.rb', line 3866 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 |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, locals: Array, class_keyword_loc: Location, constant_path: ConstantReadNode | ConstantPathNode | CallNode, inheritance_operator_loc: Location?, superclass: Prism::node?, body: StatementsNode | BeginNode | nil, end_keyword_loc: Location, name: Symbol }
3874 3875 3876 |
# File 'lib/prism/node.rb', line 3874 def deconstruct_keys(keys) { node_id: node_id, location: location, 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 |
#end_keyword ⇒ Object
def end_keyword: () -> String
3967 3968 3969 |
# File 'lib/prism/node.rb', line 3967 def end_keyword end_keyword_loc.slice end |
#end_keyword_loc ⇒ Object
Represents the location of the ‘end` keyword.
class Foo end
^^^
3939 3940 3941 3942 3943 |
# File 'lib/prism/node.rb', line 3939 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 |
#inheritance_operator ⇒ Object
def inheritance_operator: () -> String?
3962 3963 3964 |
# File 'lib/prism/node.rb', line 3962 def inheritance_operator inheritance_operator_loc&.slice end |
#inheritance_operator_loc ⇒ Object
Represents the location of the ‘<` operator.
class Foo < Bar
^
3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 |
# File 'lib/prism/node.rb', line 3904 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 |
#inspect ⇒ Object
def inspect -> String
3972 3973 3974 |
# File 'lib/prism/node.rb', line 3972 def inspect InspectVisitor.compose(self) end |
#save_class_keyword_loc(repository) ⇒ Object
Save the class_keyword_loc location using the given saved source so that it can be retrieved later.
3893 3894 3895 |
# File 'lib/prism/node.rb', line 3893 def save_class_keyword_loc(repository) repository.enter(node_id, :class_keyword_loc) end |
#save_end_keyword_loc(repository) ⇒ Object
Save the end_keyword_loc location using the given saved source so that it can be retrieved later.
3947 3948 3949 |
# File 'lib/prism/node.rb', line 3947 def save_end_keyword_loc(repository) repository.enter(node_id, :end_keyword_loc) end |
#save_inheritance_operator_loc(repository) ⇒ Object
Save the inheritance_operator_loc location using the given saved source so that it can be retrieved later.
3918 3919 3920 |
# File 'lib/prism/node.rb', line 3918 def save_inheritance_operator_loc(repository) repository.enter(node_id, :inheritance_operator_loc) unless @inheritance_operator_loc.nil? end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
3977 3978 3979 |
# File 'lib/prism/node.rb', line 3977 def type :class_node end |