Class: SyntaxTree::SClass
Overview
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
Instance Attribute Summary collapse
-
#bodystmt ⇒ Object
readonly
- BodyStmt
-
the expressions to be executed.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#target ⇒ Object
readonly
- untyped
-
the target of the singleton class to enter.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(target:, bodystmt:, location:, comments: []) ⇒ SClass
constructor
A new instance of SClass.
Methods inherited from Node
Constructor Details
#initialize(target:, bodystmt:, location:, comments: []) ⇒ SClass
Returns a new instance of SClass.
7222 7223 7224 7225 7226 7227 |
# File 'lib/syntax_tree/node.rb', line 7222 def initialize(target:, bodystmt:, location:, comments: []) @target = target @bodystmt = bodystmt @location = location @comments = comments end |
Instance Attribute Details
#bodystmt ⇒ Object (readonly)
- BodyStmt
-
the expressions to be executed
7217 7218 7219 |
# File 'lib/syntax_tree/node.rb', line 7217 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
7220 7221 7222 |
# File 'lib/syntax_tree/node.rb', line 7220 def comments @comments end |
#target ⇒ Object (readonly)
- untyped
-
the target of the singleton class to enter
7214 7215 7216 |
# File 'lib/syntax_tree/node.rb', line 7214 def target @target end |
Instance Method Details
#accept(visitor) ⇒ Object
7229 7230 7231 |
# File 'lib/syntax_tree/node.rb', line 7229 def accept(visitor) visitor.visit_sclass(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
7233 7234 7235 |
# File 'lib/syntax_tree/node.rb', line 7233 def child_nodes [target, bodystmt] end |
#deconstruct_keys(keys) ⇒ Object
7239 7240 7241 7242 7243 7244 7245 7246 |
# File 'lib/syntax_tree/node.rb', line 7239 def deconstruct_keys(keys) { target: target, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 |
# File 'lib/syntax_tree/node.rb', line 7248 def format(q) q.group(0, "class << ", "end") do q.format(target) q.indent do q.breakable(force: true) q.format(bodystmt) end q.breakable(force: true) end end |