Class: SyntaxTree::Command
Overview
Command represents a method call with arguments and no parentheses. Note that Command nodes only happen when there is no explicit receiver for this method.
method argument
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
- Args
-
the arguments being sent with the message.
-
#block ⇒ Object
readonly
- nil | BlockNode
-
the optional block being passed to the method.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#message ⇒ Object
readonly
- Const | Ident
-
the message being sent to the implicit receiver.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #arity ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(message: nil, arguments: nil, block: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(message:, arguments:, block:, location:) ⇒ Command
constructor
A new instance of Command.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(message:, arguments:, block:, location:) ⇒ Command
Returns a new instance of Command.
3479 3480 3481 3482 3483 3484 3485 |
# File 'lib/syntax_tree/node.rb', line 3479 def initialize(message:, arguments:, block:, location:) = @arguments = arguments @block = block @location = location @comments = [] end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
- Args
-
the arguments being sent with the message
3471 3472 3473 |
# File 'lib/syntax_tree/node.rb', line 3471 def arguments @arguments end |
#block ⇒ Object (readonly)
- nil | BlockNode
-
the optional block being passed to the method
3474 3475 3476 |
# File 'lib/syntax_tree/node.rb', line 3474 def block @block end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3477 3478 3479 |
# File 'lib/syntax_tree/node.rb', line 3477 def comments @comments end |
#message ⇒ Object (readonly)
- Const | Ident
-
the message being sent to the implicit receiver
3468 3469 3470 |
# File 'lib/syntax_tree/node.rb', line 3468 def end |
Instance Method Details
#===(other) ⇒ Object
3529 3530 3531 3532 |
# File 'lib/syntax_tree/node.rb', line 3529 def ===(other) other.is_a?(Command) && === other. && arguments === other.arguments && block === other.block end |
#accept(visitor) ⇒ Object
3487 3488 3489 |
# File 'lib/syntax_tree/node.rb', line 3487 def accept(visitor) visitor.visit_command(self) end |
#arity ⇒ Object
3534 3535 3536 |
# File 'lib/syntax_tree/node.rb', line 3534 def arity arguments.arity end |
#child_nodes ⇒ Object Also known as: deconstruct
3491 3492 3493 |
# File 'lib/syntax_tree/node.rb', line 3491 def child_nodes [, arguments, block] end |
#copy(message: nil, arguments: nil, block: nil, location: nil) ⇒ Object
3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 |
# File 'lib/syntax_tree/node.rb', line 3495 def copy(message: nil, arguments: nil, block: nil, location: nil) node = Command.new( 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
3510 3511 3512 3513 3514 3515 3516 3517 3518 |
# File 'lib/syntax_tree/node.rb', line 3510 def deconstruct_keys(_keys) { message: , arguments: arguments, block: block, location: location, comments: comments } end |
#format(q) ⇒ Object
3520 3521 3522 3523 3524 3525 3526 3527 |
# File 'lib/syntax_tree/node.rb', line 3520 def format(q) q.group do q.format() align(q, self) { q.format(arguments) } end q.format(block) if block end |