Class: SyntaxTree::Call
Overview
Call represents a method call.
receiver.
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
- nil | ArgParen | Args
-
the arguments to the method call.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#message ⇒ Object
readonly
- :call | Backtick | Const | Ident | Op
-
the message being sent.
-
#operator ⇒ Object
readonly
- :“::” | Op | Period
-
the operator being used to send the message.
-
#receiver ⇒ Object
readonly
- untyped
-
the receiver of the method call.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
- #format_arguments(q) ⇒ Object
- #format_contents(q) ⇒ Object
-
#initialize(receiver:, operator:, message:, arguments:, location:, comments: []) ⇒ Call
constructor
A new instance of Call.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(receiver:, operator:, message:, arguments:, location:, comments: []) ⇒ Call
Returns a new instance of Call.
2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 |
# File 'lib/syntax_tree/node.rb', line 2584 def initialize( receiver:, operator:, message:, arguments:, location:, comments: [] ) @receiver = receiver @operator = operator = @arguments = arguments @location = location @comments = comments end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
- nil | ArgParen | Args
-
the arguments to the method call
2579 2580 2581 |
# File 'lib/syntax_tree/node.rb', line 2579 def arguments @arguments end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
2582 2583 2584 |
# File 'lib/syntax_tree/node.rb', line 2582 def comments @comments end |
#message ⇒ Object (readonly)
- :call | Backtick | Const | Ident | Op
-
the message being sent
2576 2577 2578 |
# File 'lib/syntax_tree/node.rb', line 2576 def end |
#operator ⇒ Object (readonly)
- :“::” | Op | Period
-
the operator being used to send the message
2573 2574 2575 |
# File 'lib/syntax_tree/node.rb', line 2573 def operator @operator end |
#receiver ⇒ Object (readonly)
- untyped
-
the receiver of the method call
2570 2571 2572 |
# File 'lib/syntax_tree/node.rb', line 2570 def receiver @receiver end |
Instance Method Details
#accept(visitor) ⇒ Object
2600 2601 2602 |
# File 'lib/syntax_tree/node.rb', line 2600 def accept(visitor) visitor.visit_call(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
2604 2605 2606 2607 2608 2609 2610 2611 |
# File 'lib/syntax_tree/node.rb', line 2604 def child_nodes [ receiver, (operator if operator != :"::"), ( if != :call), arguments ] end |
#deconstruct_keys(_keys) ⇒ Object
2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 |
# File 'lib/syntax_tree/node.rb', line 2615 def deconstruct_keys(_keys) { receiver: receiver, operator: operator, message: , arguments: arguments, location: location, comments: comments } end |
#format(q) ⇒ Object
2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 |
# File 'lib/syntax_tree/node.rb', line 2626 def format(q) # If we're at the top of a call chain, then we're going to do some # specialized printing in case we can print it nicely. We _only_ do this # at the top of the chain to avoid weird recursion issues. if !CallChainFormatter.chained?(q.parent) && CallChainFormatter.chained?(receiver) q.group do q .if_break { CallChainFormatter.new(self).format(q) } .if_flat { format_contents(q) } end else format_contents(q) end end |
#format_arguments(q) ⇒ Object
2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 |
# File 'lib/syntax_tree/node.rb', line 2642 def format_arguments(q) case arguments in ArgParen q.format(arguments) in Args q.text(" ") q.format(arguments) else # Do nothing if there are no arguments. end end |
#format_contents(q) ⇒ Object
2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 |
# File 'lib/syntax_tree/node.rb', line 2654 def format_contents(q) call_operator = CallOperatorFormatter.new(operator) q.group do q.format(receiver) # If there are trailing comments on the call operator, then we need to # use the trailing form as opposed to the leading form. q.format(call_operator) if call_operator.comments.any? q.group do q.indent do if receiver.comments.any? || call_operator.comments.any? q.breakable(force: true) end if call_operator.comments.empty? q.format(call_operator, stackable: false) end q.format() if != :call end format_arguments(q) end end end |