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.
3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 |
# File 'lib/syntax_tree/node.rb', line 3654 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
3649 3650 3651 |
# File 'lib/syntax_tree/node.rb', line 3649 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3652 3653 3654 |
# File 'lib/syntax_tree/node.rb', line 3652 def comments @comments end |
#name ⇒ Object (readonly)
- Backtick | Const | Ident | Kw | Op
-
the name of the method
3643 3644 3645 |
# File 'lib/syntax_tree/node.rb', line 3643 def name @name end |
#operator ⇒ Object (readonly)
- Op | Period
-
the operator being used to declare the method
3640 3641 3642 |
# File 'lib/syntax_tree/node.rb', line 3640 def operator @operator end |
#params ⇒ Object (readonly)
- Params | Paren
-
the parameter declaration for the method
3646 3647 3648 |
# File 'lib/syntax_tree/node.rb', line 3646 def params @params end |
#target ⇒ Object (readonly)
- untyped
-
the target where the method is being defined
3637 3638 3639 |
# File 'lib/syntax_tree/node.rb', line 3637 def target @target end |
Instance Method Details
#accept(visitor) ⇒ Object
3672 3673 3674 |
# File 'lib/syntax_tree/node.rb', line 3672 def accept(visitor) visitor.visit_defs(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3676 3677 3678 |
# File 'lib/syntax_tree/node.rb', line 3676 def child_nodes [target, operator, name, params, bodystmt] end |
#deconstruct_keys(_keys) ⇒ Object
3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 |
# File 'lib/syntax_tree/node.rb', line 3682 def deconstruct_keys(_keys) { target: target, operator: operator, name: name, params: params, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 |
# File 'lib/syntax_tree/node.rb', line 3694 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 |