Class: SyntaxTree::Def
Overview
Def represents defining a regular method on the current self object.
def method(param) result end
Instance Attribute Summary collapse
-
#bodystmt ⇒ Object
readonly
- BodyStmt
-
the expressions to be executed by the method.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#name ⇒ Object
readonly
- Backtick | Const | Ident | Kw | Op
-
the name of the method.
-
#params ⇒ Object
readonly
- Params | Paren
-
the parameter declaration for the method.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(name:, params:, bodystmt:, location:, comments: []) ⇒ Def
constructor
A new instance of Def.
Methods inherited from Node
Constructor Details
#initialize(name:, params:, bodystmt:, location:, comments: []) ⇒ Def
Returns a new instance of Def.
3341 3342 3343 3344 3345 3346 3347 |
# File 'lib/syntax_tree/node.rb', line 3341 def initialize(name:, params:, bodystmt:, location:, comments: []) @name = name @params = params @bodystmt = bodystmt @location = location @comments = comments end |
Instance Attribute Details
#bodystmt ⇒ Object (readonly)
- BodyStmt
-
the expressions to be executed by the method
3336 3337 3338 |
# File 'lib/syntax_tree/node.rb', line 3336 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3339 3340 3341 |
# File 'lib/syntax_tree/node.rb', line 3339 def comments @comments end |
#name ⇒ Object (readonly)
- Backtick | Const | Ident | Kw | Op
-
the name of the method
3330 3331 3332 |
# File 'lib/syntax_tree/node.rb', line 3330 def name @name end |
#params ⇒ Object (readonly)
- Params | Paren
-
the parameter declaration for the method
3333 3334 3335 |
# File 'lib/syntax_tree/node.rb', line 3333 def params @params end |
Instance Method Details
#accept(visitor) ⇒ Object
3349 3350 3351 |
# File 'lib/syntax_tree/node.rb', line 3349 def accept(visitor) visitor.visit_def(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3353 3354 3355 |
# File 'lib/syntax_tree/node.rb', line 3353 def child_nodes [name, params, bodystmt] end |
#deconstruct_keys(keys) ⇒ Object
3359 3360 3361 3362 3363 3364 3365 3366 3367 |
# File 'lib/syntax_tree/node.rb', line 3359 def deconstruct_keys(keys) { name: name, params: params, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 |
# File 'lib/syntax_tree/node.rb', line 3369 def format(q) q.group do q.group do q.text("def ") q.format(name) if !params.is_a?(Params) || !params.empty? || params.comments.any? q.format(params) end end unless bodystmt.empty? q.indent do q.breakable(force: true) q.format(bodystmt) end end q.breakable(force: true) q.text("end") end end |