Class: SyntaxTree::DefEndless
Overview
DefEndless represents defining a single-line method since Ruby 3.0+.
def method = result
Instance Attribute Summary collapse
-
#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.
-
#paren ⇒ Object
readonly
- nil | Params | Paren
-
the parameter declaration for the method.
-
#statement ⇒ Object
readonly
- untyped
-
the expression to be executed by 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:, paren:, statement:, location:, comments: []) ⇒ DefEndless
constructor
A new instance of DefEndless.
Methods inherited from Node
Constructor Details
#initialize(target:, operator:, name:, paren:, statement:, location:, comments: []) ⇒ DefEndless
Returns a new instance of DefEndless.
3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 |
# File 'lib/syntax_tree/node.rb', line 3416 def initialize( target:, operator:, name:, paren:, statement:, location:, comments: [] ) @target = target @operator = operator @name = name @paren = paren @statement = statement @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3414 3415 3416 |
# File 'lib/syntax_tree/node.rb', line 3414 def comments @comments end |
#name ⇒ Object (readonly)
- Backtick | Const | Ident | Kw | Op
-
the name of the method
3405 3406 3407 |
# File 'lib/syntax_tree/node.rb', line 3405 def name @name end |
#operator ⇒ Object (readonly)
- Op | Period
-
the operator being used to declare the method
3402 3403 3404 |
# File 'lib/syntax_tree/node.rb', line 3402 def operator @operator end |
#paren ⇒ Object (readonly)
- nil | Params | Paren
-
the parameter declaration for the method
3408 3409 3410 |
# File 'lib/syntax_tree/node.rb', line 3408 def paren @paren end |
#statement ⇒ Object (readonly)
- untyped
-
the expression to be executed by the method
3411 3412 3413 |
# File 'lib/syntax_tree/node.rb', line 3411 def statement @statement end |
#target ⇒ Object (readonly)
- untyped
-
the target where the method is being defined
3399 3400 3401 |
# File 'lib/syntax_tree/node.rb', line 3399 def target @target end |
Instance Method Details
#accept(visitor) ⇒ Object
3434 3435 3436 |
# File 'lib/syntax_tree/node.rb', line 3434 def accept(visitor) visitor.visit_def_endless(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3438 3439 3440 |
# File 'lib/syntax_tree/node.rb', line 3438 def child_nodes [target, operator, name, paren, statement] end |
#deconstruct_keys(keys) ⇒ Object
3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 |
# File 'lib/syntax_tree/node.rb', line 3444 def deconstruct_keys(keys) { target: target, operator: operator, name: name, paren: paren, statement: statement, location: location, comments: comments } end |
#format(q) ⇒ Object
3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 |
# File 'lib/syntax_tree/node.rb', line 3456 def format(q) q.group do q.text("def ") if target q.format(target) q.format(CallOperatorFormatter.new(operator), stackable: false) end q.format(name) if paren params = paren params = params.contents if params.is_a?(Paren) q.format(paren) unless params.empty? end q.text(" =") q.group do q.indent do q.breakable q.format(statement) end end end end |