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
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(target:, operator:, name:, paren:, statement:, location:, comments: []) ⇒ DefEndless
Returns a new instance of DefEndless.
3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 |
# File 'lib/syntax_tree/node.rb', line 3520 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
3518 3519 3520 |
# File 'lib/syntax_tree/node.rb', line 3518 def comments @comments end |
#name ⇒ Object (readonly)
- Backtick | Const | Ident | Kw | Op
-
the name of the method
3509 3510 3511 |
# File 'lib/syntax_tree/node.rb', line 3509 def name @name end |
#operator ⇒ Object (readonly)
- Op | Period
-
the operator being used to declare the method
3506 3507 3508 |
# File 'lib/syntax_tree/node.rb', line 3506 def operator @operator end |
#paren ⇒ Object (readonly)
- nil | Params | Paren
-
the parameter declaration for the method
3512 3513 3514 |
# File 'lib/syntax_tree/node.rb', line 3512 def paren @paren end |
#statement ⇒ Object (readonly)
- untyped
-
the expression to be executed by the method
3515 3516 3517 |
# File 'lib/syntax_tree/node.rb', line 3515 def statement @statement end |
#target ⇒ Object (readonly)
- untyped
-
the target where the method is being defined
3503 3504 3505 |
# File 'lib/syntax_tree/node.rb', line 3503 def target @target end |
Instance Method Details
#accept(visitor) ⇒ Object
3538 3539 3540 |
# File 'lib/syntax_tree/node.rb', line 3538 def accept(visitor) visitor.visit_def_endless(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3542 3543 3544 |
# File 'lib/syntax_tree/node.rb', line 3542 def child_nodes [target, operator, name, paren, statement] end |
#deconstruct_keys(_keys) ⇒ Object
3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 |
# File 'lib/syntax_tree/node.rb', line 3548 def deconstruct_keys(_keys) { target: target, operator: operator, name: name, paren: paren, statement: statement, location: location, comments: comments } end |
#format(q) ⇒ Object
3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 |
# File 'lib/syntax_tree/node.rb', line 3560 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 |