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
Constructor Details
#initialize(target:, operator:, name:, params:, bodystmt:, location:, comments: []) ⇒ Defs
Returns a new instance of Defs.
3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 |
# File 'lib/syntax_tree/node.rb', line 3198 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
3193 3194 3195 |
# File 'lib/syntax_tree/node.rb', line 3193 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3196 3197 3198 |
# File 'lib/syntax_tree/node.rb', line 3196 def comments @comments end |
#name ⇒ Object (readonly)
- Backtick | Const | Ident | Kw | Op
-
the name of the method
3187 3188 3189 |
# File 'lib/syntax_tree/node.rb', line 3187 def name @name end |
#operator ⇒ Object (readonly)
- Op | Period
-
the operator being used to declare the method
3184 3185 3186 |
# File 'lib/syntax_tree/node.rb', line 3184 def operator @operator end |
#params ⇒ Object (readonly)
- Params | Paren
-
the parameter declaration for the method
3190 3191 3192 |
# File 'lib/syntax_tree/node.rb', line 3190 def params @params end |
#target ⇒ Object (readonly)
- untyped
-
the target where the method is being defined
3181 3182 3183 |
# File 'lib/syntax_tree/node.rb', line 3181 def target @target end |
Instance Method Details
#accept(visitor) ⇒ Object
3216 3217 3218 |
# File 'lib/syntax_tree/node.rb', line 3216 def accept(visitor) visitor.visit_defs(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3220 3221 3222 |
# File 'lib/syntax_tree/node.rb', line 3220 def child_nodes [target, operator, name, params, bodystmt] end |
#deconstruct_keys(keys) ⇒ Object
3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 |
# File 'lib/syntax_tree/node.rb', line 3226 def deconstruct_keys(keys) { target: target, operator: operator, name: name, params: params, bodystmt: bodystmt, location: location, comments: comments } end |
#format(q) ⇒ Object
3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 |
# File 'lib/syntax_tree/node.rb', line 3238 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) 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 |