Class: SyntaxTree::SClass
- Inherits:
-
Object
- Object
- SyntaxTree::SClass
- Defined in:
- lib/syntax_tree.rb
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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#target ⇒ Object
readonly
- untyped
-
the target of the singleton class to enter.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(target:, bodystmt:, location:, comments: []) ⇒ SClass
constructor
A new instance of SClass.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(target:, bodystmt:, location:, comments: []) ⇒ SClass
Returns a new instance of SClass.
10215 10216 10217 10218 10219 10220 |
# File 'lib/syntax_tree.rb', line 10215 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
10207 10208 10209 |
# File 'lib/syntax_tree.rb', line 10207 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
10213 10214 10215 |
# File 'lib/syntax_tree.rb', line 10213 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
10210 10211 10212 |
# File 'lib/syntax_tree.rb', line 10210 def location @location end |
#target ⇒ Object (readonly)
- untyped
-
the target of the singleton class to enter
10204 10205 10206 |
# File 'lib/syntax_tree.rb', line 10204 def target @target end |
Instance Method Details
#child_nodes ⇒ Object
10222 10223 10224 |
# File 'lib/syntax_tree.rb', line 10222 def child_nodes [target, bodystmt] end |
#format(q) ⇒ Object
10226 10227 10228 10229 10230 10231 10232 10233 10234 10235 |
# File 'lib/syntax_tree.rb', line 10226 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 |
#pretty_print(q) ⇒ Object
10237 10238 10239 10240 10241 10242 10243 10244 10245 10246 10247 10248 10249 |
# File 'lib/syntax_tree.rb', line 10237 def pretty_print(q) q.group(2, "(", ")") do q.text("sclass") q.breakable q.pp(target) q.breakable q.pp(bodystmt) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
10251 10252 10253 10254 10255 10256 10257 10258 10259 |
# File 'lib/syntax_tree.rb', line 10251 def to_json(*opts) { type: :sclass, target: target, bodystmt: bodystmt, loc: location, cmts: comments }.to_json(*opts) end |