Class: Prism::SingletonClassNode

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

Class Method Summary collapse

Instance Method Summary collapse

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.



14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
# File 'lib/prism/node.rb', line 14777

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

#bodyObject (readonly)

attr_reader body: StatementsNode | BeginNode | nil



14847
14848
14849
# File 'lib/prism/node.rb', line 14847

def body
  @body
end

#expressionObject (readonly)

attr_reader expression: Prism::node



14844
14845
14846
# File 'lib/prism/node.rb', line 14844

def expression
  @expression
end

#localsObject (readonly)

attr_reader locals: Array



14827
14828
14829
# File 'lib/prism/node.rb', line 14827

def locals
  @locals
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



14882
14883
14884
# File 'lib/prism/node.rb', line 14882

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.



14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
# File 'lib/prism/node.rb', line 14888

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



14791
14792
14793
# File 'lib/prism/node.rb', line 14791

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

#child_nodesObject Also known as: deconstruct

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



14796
14797
14798
# File 'lib/prism/node.rb', line 14796

def child_nodes
  [expression, body]
end

#class_keywordObject

def class_keyword: () -> String



14857
14858
14859
# File 'lib/prism/node.rb', line 14857

def class_keyword
  class_keyword_loc.slice
end

#class_keyword_locObject

attr_reader class_keyword_loc: Location



14830
14831
14832
14833
14834
# File 'lib/prism/node.rb', line 14830

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_targetsObject

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



14809
14810
14811
# File 'lib/prism/node.rb', line 14809

def comment_targets
  [class_keyword_loc, operator_loc, expression, *body, end_keyword_loc] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



14801
14802
14803
14804
14805
14806
# File 'lib/prism/node.rb', line 14801

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: StatementsNode | BeginNode | nil, ?end_keyword_loc: Location) -> SingletonClassNode



14814
14815
14816
# File 'lib/prism/node.rb', line 14814

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

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, locals: Array, class_keyword_loc: Location, operator_loc: Location, expression: Prism::node, body: StatementsNode | BeginNode | nil, end_keyword_loc: Location }



14822
14823
14824
# File 'lib/prism/node.rb', line 14822

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_keywordObject

def end_keyword: () -> String



14867
14868
14869
# File 'lib/prism/node.rb', line 14867

def end_keyword
  end_keyword_loc.slice
end

#end_keyword_locObject

attr_reader end_keyword_loc: Location



14850
14851
14852
14853
14854
# File 'lib/prism/node.rb', line 14850

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

#inspectObject

def inspect -> String



14872
14873
14874
# File 'lib/prism/node.rb', line 14872

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



14862
14863
14864
# File 'lib/prism/node.rb', line 14862

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



14837
14838
14839
14840
14841
# File 'lib/prism/node.rb', line 14837

def operator_loc
  location = @operator_loc
  return location if location.is_a?(Location)
  @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



14877
14878
14879
# File 'lib/prism/node.rb', line 14877

def type
  :singleton_class_node
end