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
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(receiver:, operator:, message:, arguments:, location:, comments: []) ⇒ Call
constructor
A new instance of Call.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(receiver:, operator:, message:, arguments:, location:, comments: []) ⇒ Call
Returns a new instance of Call.
2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 |
# File 'lib/syntax_tree/node.rb', line 2645 def initialize( receiver:, operator:, message:, arguments:, location:, comments: [] ) @receiver = receiver @operator = operator @message = @arguments = arguments @location = location @comments = comments end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
- nil | ArgParen | Args
-
the arguments to the method call
2640 2641 2642 |
# File 'lib/syntax_tree/node.rb', line 2640 def arguments @arguments end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
2643 2644 2645 |
# File 'lib/syntax_tree/node.rb', line 2643 def comments @comments end |
#message ⇒ Object (readonly)
- :call | Backtick | Const | Ident | Op
-
the message being sent
2637 2638 2639 |
# File 'lib/syntax_tree/node.rb', line 2637 def @message end |
#operator ⇒ Object (readonly)
- :“::” | Op | Period
-
the operator being used to send the message
2634 2635 2636 |
# File 'lib/syntax_tree/node.rb', line 2634 def operator @operator end |
#receiver ⇒ Object (readonly)
- untyped
-
the receiver of the method call
2631 2632 2633 |
# File 'lib/syntax_tree/node.rb', line 2631 def receiver @receiver end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
2661 2662 2663 2664 2665 2666 2667 2668 |
# File 'lib/syntax_tree/node.rb', line 2661 def child_nodes [ receiver, (operator if operator != :"::"), ( if != :call), arguments ] end |
#deconstruct_keys(keys) ⇒ Object
2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 |
# File 'lib/syntax_tree/node.rb', line 2672 def deconstruct_keys(keys) { receiver: receiver, operator: operator, message: , arguments: arguments, location: location, comments: comments } end |
#format(q) ⇒ Object
2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 |
# File 'lib/syntax_tree/node.rb', line 2683 def format(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 q.format(arguments) if arguments end end end |
#pretty_print(q) ⇒ Object
2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 |
# File 'lib/syntax_tree/node.rb', line 2711 def pretty_print(q) q.group(2, "(", ")") do q.text("call") q.breakable q.pp(receiver) q.breakable q.pp(operator) q.breakable q.pp() if arguments q.breakable q.pp(arguments) end q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 |
# File 'lib/syntax_tree/node.rb', line 2733 def to_json(*opts) { type: :call, receiver: receiver, op: operator, message: , args: arguments, loc: location, cmts: comments }.to_json(*opts) end |