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 | Block
-
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, #pretty_print, #to_json
Constructor Details
#initialize(message:, arguments:, block:, location:) ⇒ Command
Returns a new instance of Command.
3387 3388 3389 3390 3391 3392 3393 |
# File 'lib/syntax_tree/node.rb', line 3387 def initialize(message:, arguments:, block:, location:) @message = @arguments = arguments @block = block @location = location @comments = [] end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
- Args
-
the arguments being sent with the message
3379 3380 3381 |
# File 'lib/syntax_tree/node.rb', line 3379 def arguments @arguments end |
#block ⇒ Object (readonly)
- nil | Block
-
the optional block being passed to the method
3382 3383 3384 |
# File 'lib/syntax_tree/node.rb', line 3382 def block @block end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3385 3386 3387 |
# File 'lib/syntax_tree/node.rb', line 3385 def comments @comments end |
#message ⇒ Object (readonly)
- Const | Ident
-
the message being sent to the implicit receiver
3376 3377 3378 |
# File 'lib/syntax_tree/node.rb', line 3376 def @message end |
Instance Method Details
#===(other) ⇒ Object
3437 3438 3439 3440 |
# File 'lib/syntax_tree/node.rb', line 3437 def ===(other) other.is_a?(Command) && === other. && arguments === other.arguments && block === other.block end |
#accept(visitor) ⇒ Object
3395 3396 3397 |
# File 'lib/syntax_tree/node.rb', line 3395 def accept(visitor) visitor.visit_command(self) end |
#arity ⇒ Object
3442 3443 3444 |
# File 'lib/syntax_tree/node.rb', line 3442 def arity arguments.arity end |
#child_nodes ⇒ Object Also known as: deconstruct
3399 3400 3401 |
# File 'lib/syntax_tree/node.rb', line 3399 def child_nodes [, arguments, block] end |
#copy(message: nil, arguments: nil, block: nil, location: nil) ⇒ Object
3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 |
# File 'lib/syntax_tree/node.rb', line 3403 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
3418 3419 3420 3421 3422 3423 3424 3425 3426 |
# File 'lib/syntax_tree/node.rb', line 3418 def deconstruct_keys(_keys) { message: , arguments: arguments, block: block, location: location, comments: comments } end |
#format(q) ⇒ Object
3428 3429 3430 3431 3432 3433 3434 3435 |
# File 'lib/syntax_tree/node.rb', line 3428 def format(q) q.group do q.format() align(q, self) { q.format(arguments) } end q.format(block) if block end |