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
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(name:, params:, bodystmt:, location:, comments: []) ⇒ Def
Returns a new instance of Def.
3538 3539 3540 3541 3542 3543 3544 |
# File 'lib/syntax_tree/node.rb', line 3538 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
3533 3534 3535 |
# File 'lib/syntax_tree/node.rb', line 3533 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3536 3537 3538 |
# File 'lib/syntax_tree/node.rb', line 3536 def comments @comments end |
#name ⇒ Object (readonly)
- Backtick | Const | Ident | Kw | Op
-
the name of the method
3527 3528 3529 |
# File 'lib/syntax_tree/node.rb', line 3527 def name @name end |
#params ⇒ Object (readonly)
- Params | Paren
-
the parameter declaration for the method
3530 3531 3532 |
# File 'lib/syntax_tree/node.rb', line 3530 def params @params end |
Instance Method Details
#accept(visitor) ⇒ Object
3546 3547 3548 |
# File 'lib/syntax_tree/node.rb', line 3546 def accept(visitor) visitor.visit_def(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3550 3551 3552 |
# File 'lib/syntax_tree/node.rb', line 3550 def child_nodes [name, params, bodystmt] end |
#deconstruct_keys(_keys) ⇒ Object
3556 3557 3558 3559 3560 3561 3562 3563 3564 |
# File 'lib/syntax_tree/node.rb', line 3556 def deconstruct_keys(_keys) { name: name, params: params, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 |
# File 'lib/syntax_tree/node.rb', line 3566 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 q.format(bodystmt) end end q.breakable_force q.text("end") end end |