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.
2992 2993 2994 2995 2996 2997 2998 |
# File 'lib/syntax_tree/node.rb', line 2992 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
2987 2988 2989 |
# File 'lib/syntax_tree/node.rb', line 2987 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
2990 2991 2992 |
# File 'lib/syntax_tree/node.rb', line 2990 def comments @comments end |
#name ⇒ Object (readonly)
- Backtick | Const | Ident | Kw | Op
-
the name of the method
2981 2982 2983 |
# File 'lib/syntax_tree/node.rb', line 2981 def name @name end |
#params ⇒ Object (readonly)
- Params | Paren
-
the parameter declaration for the method
2984 2985 2986 |
# File 'lib/syntax_tree/node.rb', line 2984 def params @params end |
Instance Method Details
#accept(visitor) ⇒ Object
3000 3001 3002 |
# File 'lib/syntax_tree/node.rb', line 3000 def accept(visitor) visitor.visit_def(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3004 3005 3006 |
# File 'lib/syntax_tree/node.rb', line 3004 def child_nodes [name, params, bodystmt] end |
#deconstruct_keys(keys) ⇒ Object
3010 3011 3012 3013 3014 3015 3016 3017 3018 |
# File 'lib/syntax_tree/node.rb', line 3010 def deconstruct_keys(keys) { name: name, params: params, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 |
# File 'lib/syntax_tree/node.rb', line 3020 def format(q) q.group do q.group do q.text("def ") q.format(name) q.format(params) if !params.is_a?(Params) || !params.empty? 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 |