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.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#message ⇒ Object
readonly
- Const | Ident
-
the message being sent to the implicit receiver.
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(message:, arguments:, location:, comments: []) ⇒ Command
constructor
A new instance of Command.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(message:, arguments:, location:, comments: []) ⇒ Command
Returns a new instance of Command.
3188 3189 3190 3191 3192 3193 |
# File 'lib/syntax_tree/node.rb', line 3188 def initialize(message:, arguments:, location:, comments: []) @message = @arguments = arguments @location = location @comments = comments end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
- Args
-
the arguments being sent with the message
3180 3181 3182 |
# File 'lib/syntax_tree/node.rb', line 3180 def arguments @arguments end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3186 3187 3188 |
# File 'lib/syntax_tree/node.rb', line 3186 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
3183 3184 3185 |
# File 'lib/syntax_tree/node.rb', line 3183 def location @location end |
#message ⇒ Object (readonly)
- Const | Ident
-
the message being sent to the implicit receiver
3177 3178 3179 |
# File 'lib/syntax_tree/node.rb', line 3177 def @message end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
3195 3196 3197 |
# File 'lib/syntax_tree/node.rb', line 3195 def child_nodes [, arguments] end |
#deconstruct_keys(keys) ⇒ Object
3201 3202 3203 3204 3205 3206 3207 3208 |
# File 'lib/syntax_tree/node.rb', line 3201 def deconstruct_keys(keys) { message: , arguments: arguments, location: location, comments: comments } end |
#format(q) ⇒ Object
3210 3211 3212 3213 3214 3215 3216 |
# File 'lib/syntax_tree/node.rb', line 3210 def format(q) q.group do q.format() q.text(" ") q.nest(.value.length + 1) { q.format(arguments) } end end |
#pretty_print(q) ⇒ Object
3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 |
# File 'lib/syntax_tree/node.rb', line 3218 def pretty_print(q) q.group(2, "(", ")") do q.text("command") q.breakable q.pp() q.breakable q.pp(arguments) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
3232 3233 3234 3235 3236 3237 3238 3239 3240 |
# File 'lib/syntax_tree/node.rb', line 3232 def to_json(*opts) { type: :command, message: , args: arguments, loc: location, cmts: comments }.to_json(*opts) end |