Class: SyntaxTree::DefEndless
- Inherits:
-
Object
- Object
- SyntaxTree::DefEndless
- Defined in:
- lib/syntax_tree.rb
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.
-
#location ⇒ Object
readonly
- Location
-
the location of 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.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(target:, operator:, name:, paren:, statement:, location:, comments: []) ⇒ DefEndless
constructor
A new instance of DefEndless.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(target:, operator:, name:, paren:, statement:, location:, comments: []) ⇒ DefEndless
Returns a new instance of DefEndless.
4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 |
# File 'lib/syntax_tree.rb', line 4559 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
4557 4558 4559 |
# File 'lib/syntax_tree.rb', line 4557 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
4554 4555 4556 |
# File 'lib/syntax_tree.rb', line 4554 def location @location end |
#name ⇒ Object (readonly)
- Backtick | Const | Ident | Kw | Op
-
the name of the method
4545 4546 4547 |
# File 'lib/syntax_tree.rb', line 4545 def name @name end |
#operator ⇒ Object (readonly)
- Op | Period
-
the operator being used to declare the method
4542 4543 4544 |
# File 'lib/syntax_tree.rb', line 4542 def operator @operator end |
#paren ⇒ Object (readonly)
- nil | Params | Paren
-
the parameter declaration for the method
4548 4549 4550 |
# File 'lib/syntax_tree.rb', line 4548 def paren @paren end |
#statement ⇒ Object (readonly)
- untyped
-
the expression to be executed by the method
4551 4552 4553 |
# File 'lib/syntax_tree.rb', line 4551 def statement @statement end |
#target ⇒ Object (readonly)
- untyped
-
the target where the method is being defined
4539 4540 4541 |
# File 'lib/syntax_tree.rb', line 4539 def target @target end |
Instance Method Details
#child_nodes ⇒ Object
4577 4578 4579 |
# File 'lib/syntax_tree.rb', line 4577 def child_nodes [target, operator, name, paren, statement] end |
#format(q) ⇒ Object
4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 |
# File 'lib/syntax_tree.rb', line 4581 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 |
#pretty_print(q) ⇒ Object
4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 |
# File 'lib/syntax_tree.rb', line 4608 def pretty_print(q) q.group(2, "(", ")") do q.text("def_endless") if target q.breakable q.pp(target) q.breakable q.pp(operator) end q.breakable q.pp(name) if paren q.breakable q.pp(paren) end q.breakable q.pp(statement) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 |
# File 'lib/syntax_tree.rb', line 4635 def to_json(*opts) { type: :def_endless, name: name, paren: paren, stmt: statement, loc: location, cmts: comments }.to_json(*opts) end |