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.
3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 |
# File 'lib/syntax_tree/node.rb', line 3749 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
3744 3745 3746 |
# File 'lib/syntax_tree/node.rb', line 3744 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3747 3748 3749 |
# File 'lib/syntax_tree/node.rb', line 3747 def comments @comments end |
#name ⇒ Object (readonly)
- Backtick | Const | Ident | Kw | Op
-
the name of the method
3738 3739 3740 |
# File 'lib/syntax_tree/node.rb', line 3738 def name @name end |
#operator ⇒ Object (readonly)
- Op | Period
-
the operator being used to declare the method
3735 3736 3737 |
# File 'lib/syntax_tree/node.rb', line 3735 def operator @operator end |
#params ⇒ Object (readonly)
- Params | Paren
-
the parameter declaration for the method
3741 3742 3743 |
# File 'lib/syntax_tree/node.rb', line 3741 def params @params end |
#target ⇒ Object (readonly)
- untyped
-
the target where the method is being defined
3732 3733 3734 |
# File 'lib/syntax_tree/node.rb', line 3732 def target @target end |
Instance Method Details
#accept(visitor) ⇒ Object
3767 3768 3769 |
# File 'lib/syntax_tree/node.rb', line 3767 def accept(visitor) visitor.visit_defs(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3771 3772 3773 |
# File 'lib/syntax_tree/node.rb', line 3771 def child_nodes [target, operator, name, params, bodystmt] end |
#deconstruct_keys(_keys) ⇒ Object
3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 |
# File 'lib/syntax_tree/node.rb', line 3777 def deconstruct_keys(_keys) { target: target, operator: operator, name: name, params: params, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 |
# File 'lib/syntax_tree/node.rb', line 3789 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 q.format(bodystmt) end end q.breakable_force q.text("end") end end |