Class: SyntaxTree::CommandCall
Overview
CommandCall represents a method call on an object with arguments and no parentheses.
object.method argument
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
- nil | Args | ArgParen
-
the arguments going along with the message.
-
#block ⇒ Object
readonly
- nil | BlockNode
-
the block associated with this method call.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#message ⇒ Object
readonly
- :call | Const | Ident | Op
-
the message being send.
-
#operator ⇒ Object
readonly
- nil | :“::” | Op | Period
-
the operator used to send the message.
-
#receiver ⇒ Object
readonly
- nil | Node
-
the receiver of the message.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #arity ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(receiver: nil, operator: nil, message: nil, arguments: nil, block: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(receiver:, operator:, message:, arguments:, block:, location:) ⇒ CommandCall
constructor
A new instance of CommandCall.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(receiver:, operator:, message:, arguments:, block:, location:) ⇒ CommandCall
Returns a new instance of CommandCall.
3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 |
# File 'lib/syntax_tree/node.rb', line 3582 def initialize( receiver:, operator:, message:, arguments:, block:, location: ) @receiver = receiver @operator = operator @message = @arguments = arguments @block = block @location = location @comments = [] end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
- nil | Args | ArgParen
-
the arguments going along with the message
3574 3575 3576 |
# File 'lib/syntax_tree/node.rb', line 3574 def arguments @arguments end |
#block ⇒ Object (readonly)
- nil | BlockNode
-
the block associated with this method call
3577 3578 3579 |
# File 'lib/syntax_tree/node.rb', line 3577 def block @block end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3580 3581 3582 |
# File 'lib/syntax_tree/node.rb', line 3580 def comments @comments end |
#message ⇒ Object (readonly)
- :call | Const | Ident | Op
-
the message being send
3571 3572 3573 |
# File 'lib/syntax_tree/node.rb', line 3571 def @message end |
#operator ⇒ Object (readonly)
- nil | :“::” | Op | Period
-
the operator used to send the message
3568 3569 3570 |
# File 'lib/syntax_tree/node.rb', line 3568 def operator @operator end |
#receiver ⇒ Object (readonly)
- nil | Node
-
the receiver of the message
3565 3566 3567 |
# File 'lib/syntax_tree/node.rb', line 3565 def receiver @receiver end |
Instance Method Details
#===(other) ⇒ Object
3686 3687 3688 3689 3690 |
# File 'lib/syntax_tree/node.rb', line 3686 def ===(other) other.is_a?(CommandCall) && receiver === other.receiver && operator === other.operator && === other. && arguments === other.arguments && block === other.block end |
#accept(visitor) ⇒ Object
3599 3600 3601 |
# File 'lib/syntax_tree/node.rb', line 3599 def accept(visitor) visitor.visit_command_call(self) end |
#arity ⇒ Object
3692 3693 3694 |
# File 'lib/syntax_tree/node.rb', line 3692 def arity arguments&.arity || 0 end |
#child_nodes ⇒ Object Also known as: deconstruct
3603 3604 3605 |
# File 'lib/syntax_tree/node.rb', line 3603 def child_nodes [receiver, , arguments, block] end |
#copy(receiver: nil, operator: nil, message: nil, arguments: nil, block: nil, location: nil) ⇒ Object
3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 |
# File 'lib/syntax_tree/node.rb', line 3607 def copy( receiver: nil, operator: nil, message: nil, arguments: nil, block: nil, location: nil ) node = CommandCall.new( receiver: receiver || self.receiver, operator: operator || self.operator, message: || self., arguments: arguments || self.arguments, block: block || self.block, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 |
# File 'lib/syntax_tree/node.rb', line 3631 def deconstruct_keys(_keys) { receiver: receiver, operator: operator, message: , arguments: arguments, block: block, location: location, comments: comments } end |
#format(q) ⇒ Object
3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 |
# File 'lib/syntax_tree/node.rb', line 3643 def format(q) = self. arguments = self.arguments block = self.block q.group do doc = q.nest(0) do q.format(receiver) # If there are leading comments on the message then we know we have # a newline in the source that is forcing these things apart. In # this case we will have to use a trailing operator. if != :call && .comments.any?(&:leading?) q.format(CallOperatorFormatter.new(operator), stackable: false) q.indent do q.breakable_empty q.format() end else q.format(CallOperatorFormatter.new(operator), stackable: false) q.format() end end # Format the arguments for this command call here. If there are no # arguments, then print nothing. if arguments parts = arguments.parts if parts.length == 1 && parts.first.is_a?(IfOp) q.if_flat { q.text(" ") } q.format(arguments) else q.text(" ") q.nest(argument_alignment(q, doc)) { q.format(arguments) } end end end q.format(block) if block end |