class SyntaxTree::SClass

SClass represents a block of statements that should be evaluated within the context of the singleton class of an object. It’s frequently used to define singleton methods.

class << self
end

Attributes

bodystmt[R]
BodyStmt

the expressions to be executed

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

target[R]
Node

the target of the singleton class to enter

Public Class Methods

new(target:, bodystmt:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 9803
def initialize(target:, bodystmt:, location:)
  @target = target
  @bodystmt = bodystmt
  @location = location
  @comments = []
end

Public Instance Methods

===(other) click to toggle source
# File lib/syntax_tree/node.rb, line 9854
def ===(other)
  other.is_a?(SClass) && target === other.target &&
    bodystmt === other.bodystmt
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 9810
def accept(visitor)
  visitor.visit_sclass(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 9814
def child_nodes
  [target, bodystmt]
end
Also aliased as: deconstruct
copy(target: nil, bodystmt: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 9818
def copy(target: nil, bodystmt: nil, location: nil)
  node =
    SClass.new(
      target: target || self.target,
      bodystmt: bodystmt || self.bodystmt,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end
deconstruct()
Alias for: child_nodes
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/node.rb, line 9832
def deconstruct_keys(_keys)
  {
    target: target,
    bodystmt: bodystmt,
    location: location,
    comments: comments
  }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 9841
def format(q)
  q.text("class << ")
  q.group do
    q.format(target)
    q.indent do
      q.breakable_force
      q.format(bodystmt)
    end
    q.breakable_force
  end
  q.text("end")
end