Class: SyntaxTree::Defs
Overview
Defs represents defining a singleton method on an object.
def object.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.
-
#operator ⇒ Object
readonly
- Op | Period
-
the operator being used to declare the method.
-
#params ⇒ Object
readonly
- Params | Paren
-
the parameter declaration for the method.
-
#target ⇒ Object
readonly
- untyped
-
the target where the method is being defined.
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:, operator:, name:, params:, bodystmt:, location:, comments: []) ⇒ Defs
constructor
A new instance of Defs.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(target:, operator:, name:, params:, bodystmt:, location:, comments: []) ⇒ Defs
Returns a new instance of Defs.
3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 |
# File 'lib/syntax_tree/node.rb', line 3582 def initialize( target:, operator:, name:, params:, bodystmt:, location:, comments: [] ) @target = target @operator = operator @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
3577 3578 3579 |
# File 'lib/syntax_tree/node.rb', line 3577 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3580 3581 3582 |
# File 'lib/syntax_tree/node.rb', line 3580 def comments @comments end |
#name ⇒ Object (readonly)
- Backtick | Const | Ident | Kw | Op
-
the name of the method
3571 3572 3573 |
# File 'lib/syntax_tree/node.rb', line 3571 def name @name end |
#operator ⇒ Object (readonly)
- Op | Period
-
the operator being used to declare the method
3568 3569 3570 |
# File 'lib/syntax_tree/node.rb', line 3568 def operator @operator end |
#params ⇒ Object (readonly)
- Params | Paren
-
the parameter declaration for the method
3574 3575 3576 |
# File 'lib/syntax_tree/node.rb', line 3574 def params @params end |
#target ⇒ Object (readonly)
- untyped
-
the target where the method is being defined
3565 3566 3567 |
# File 'lib/syntax_tree/node.rb', line 3565 def target @target end |
Instance Method Details
#accept(visitor) ⇒ Object
3600 3601 3602 |
# File 'lib/syntax_tree/node.rb', line 3600 def accept(visitor) visitor.visit_defs(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3604 3605 3606 |
# File 'lib/syntax_tree/node.rb', line 3604 def child_nodes [target, operator, name, params, bodystmt] end |
#deconstruct_keys(_keys) ⇒ Object
3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 |
# File 'lib/syntax_tree/node.rb', line 3610 def deconstruct_keys(_keys) { target: target, operator: operator, name: name, params: params, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 |
# File 'lib/syntax_tree/node.rb', line 3622 def format(q) q.group do q.group do q.text("def ") q.format(target) q.format(CallOperatorFormatter.new(operator), stackable: false) 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 |