Class: Prism::SingletonClassNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::SingletonClassNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents a singleton class declaration involving the ‘class` keyword.
class << self end
^^^^^^^^^^^^^^^^^
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
attr_reader body: Prism::node?.
-
#expression ⇒ Object
readonly
attr_reader expression: Prism::node.
-
#locals ⇒ Object
readonly
attr_reader locals: Array.
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[nil | Node].
-
#class_keyword ⇒ Object
def class_keyword: () -> String.
-
#class_keyword_loc ⇒ Object
attr_reader class_keyword_loc: Location.
-
#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, operator_loc: self.operator_loc, expression: self.expression, body: self.body, end_keyword_loc: self.end_keyword_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?class_keyword_loc: Location, ?operator_loc: Location, ?expression: Prism::node, ?body: Prism::node?, ?end_keyword_loc: Location) -> SingletonClassNode.
- #deconstruct_keys(keys) ⇒ Object
-
#end_keyword ⇒ Object
def end_keyword: () -> String.
-
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location.
-
#initialize(source, node_id, location, flags, locals, class_keyword_loc, operator_loc, expression, body, end_keyword_loc) ⇒ SingletonClassNode
constructor
Initialize a new SingletonClassNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#operator ⇒ Object
def operator: () -> String.
-
#operator_loc ⇒ Object
attr_reader operator_loc: Location.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, locals, class_keyword_loc, operator_loc, expression, body, end_keyword_loc) ⇒ SingletonClassNode
Initialize a new SingletonClassNode node.
14740 14741 14742 14743 14744 14745 14746 14747 14748 14749 14750 14751 |
# File 'lib/prism/node.rb', line 14740 def initialize(source, node_id, location, flags, locals, class_keyword_loc, operator_loc, expression, body, end_keyword_loc) @source = source @node_id = node_id @location = location @flags = flags @locals = locals @class_keyword_loc = class_keyword_loc @operator_loc = operator_loc @expression = expression @body = body @end_keyword_loc = end_keyword_loc end |
Instance Attribute Details
#body ⇒ Object (readonly)
attr_reader body: Prism::node?
14810 14811 14812 |
# File 'lib/prism/node.rb', line 14810 def body @body end |
#expression ⇒ Object (readonly)
attr_reader expression: Prism::node
14807 14808 14809 |
# File 'lib/prism/node.rb', line 14807 def expression @expression end |
#locals ⇒ Object (readonly)
attr_reader locals: Array
14790 14791 14792 |
# File 'lib/prism/node.rb', line 14790 def locals @locals end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
14845 14846 14847 |
# File 'lib/prism/node.rb', line 14845 def self.type :singleton_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.
14851 14852 14853 14854 14855 14856 14857 14858 14859 14860 |
# File 'lib/prism/node.rb', line 14851 def ===(other) other.is_a?(SingletonClassNode) && (locals.length == other.locals.length) && locals.zip(other.locals).all? { |left, right| left === right } && (class_keyword_loc.nil? == other.class_keyword_loc.nil?) && (operator_loc.nil? == other.operator_loc.nil?) && (expression === other.expression) && (body === other.body) && (end_keyword_loc.nil? == other.end_keyword_loc.nil?) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
14754 14755 14756 |
# File 'lib/prism/node.rb', line 14754 def accept(visitor) visitor.visit_singleton_class_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
14759 14760 14761 |
# File 'lib/prism/node.rb', line 14759 def child_nodes [expression, body] end |
#class_keyword ⇒ Object
def class_keyword: () -> String
14820 14821 14822 |
# File 'lib/prism/node.rb', line 14820 def class_keyword class_keyword_loc.slice end |
#class_keyword_loc ⇒ Object
attr_reader class_keyword_loc: Location
14793 14794 14795 14796 14797 |
# File 'lib/prism/node.rb', line 14793 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]
14772 14773 14774 |
# File 'lib/prism/node.rb', line 14772 def comment_targets [class_keyword_loc, operator_loc, expression, *body, end_keyword_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
14764 14765 14766 14767 14768 14769 |
# File 'lib/prism/node.rb', line 14764 def compact_child_nodes compact = [] #: Array[Prism::node] compact << expression 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, operator_loc: self.operator_loc, expression: self.expression, body: self.body, end_keyword_loc: self.end_keyword_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?locals: Array, ?class_keyword_loc: Location, ?operator_loc: Location, ?expression: Prism::node, ?body: Prism::node?, ?end_keyword_loc: Location) -> SingletonClassNode
14777 14778 14779 |
# File 'lib/prism/node.rb', line 14777 def copy(node_id: self.node_id, location: self.location, flags: self.flags, locals: self.locals, class_keyword_loc: self.class_keyword_loc, operator_loc: self.operator_loc, expression: self.expression, body: self.body, end_keyword_loc: self.end_keyword_loc) SingletonClassNode.new(source, node_id, location, flags, locals, class_keyword_loc, operator_loc, expression, body, end_keyword_loc) end |
#deconstruct_keys(keys) ⇒ Object
14785 14786 14787 |
# File 'lib/prism/node.rb', line 14785 def deconstruct_keys(keys) { node_id: node_id, location: location, locals: locals, class_keyword_loc: class_keyword_loc, operator_loc: operator_loc, expression: expression, body: body, end_keyword_loc: end_keyword_loc } end |
#end_keyword ⇒ Object
def end_keyword: () -> String
14830 14831 14832 |
# File 'lib/prism/node.rb', line 14830 def end_keyword end_keyword_loc.slice end |
#end_keyword_loc ⇒ Object
attr_reader end_keyword_loc: Location
14813 14814 14815 14816 14817 |
# File 'lib/prism/node.rb', line 14813 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 |
#inspect ⇒ Object
def inspect -> String
14835 14836 14837 |
# File 'lib/prism/node.rb', line 14835 def inspect InspectVisitor.compose(self) end |
#operator ⇒ Object
def operator: () -> String
14825 14826 14827 |
# File 'lib/prism/node.rb', line 14825 def operator operator_loc.slice end |
#operator_loc ⇒ Object
attr_reader operator_loc: Location
14800 14801 14802 14803 14804 |
# File 'lib/prism/node.rb', line 14800 def operator_loc location = @operator_loc return location if location.is_a?(Location) @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
14840 14841 14842 |
# File 'lib/prism/node.rb', line 14840 def type :singleton_class_node end |