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
-
the arguments going along with the message.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#message ⇒ Object
readonly
- Const | Ident | Op
-
the message being send.
-
#operator ⇒ Object
readonly
- :“::” | Op | Period
-
the operator used to send the message.
-
#receiver ⇒ Object
readonly
- untyped
-
the receiver of the message.
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: []) ⇒ CommandCall
constructor
A new instance of CommandCall.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(receiver:, operator:, message:, arguments:, location:, comments: []) ⇒ CommandCall
Returns a new instance of CommandCall.
3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 |
# File 'lib/syntax_tree/node.rb', line 3165 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 | Args
-
the arguments going along with the message
3160 3161 3162 |
# File 'lib/syntax_tree/node.rb', line 3160 def arguments @arguments end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3163 3164 3165 |
# File 'lib/syntax_tree/node.rb', line 3163 def comments @comments end |
#message ⇒ Object (readonly)
- Const | Ident | Op
-
the message being send
3157 3158 3159 |
# File 'lib/syntax_tree/node.rb', line 3157 def @message end |
#operator ⇒ Object (readonly)
- :“::” | Op | Period
-
the operator used to send the message
3154 3155 3156 |
# File 'lib/syntax_tree/node.rb', line 3154 def operator @operator end |
#receiver ⇒ Object (readonly)
- untyped
-
the receiver of the message
3151 3152 3153 |
# File 'lib/syntax_tree/node.rb', line 3151 def receiver @receiver end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
3181 3182 3183 |
# File 'lib/syntax_tree/node.rb', line 3181 def child_nodes [receiver, , arguments] end |
#deconstruct_keys(keys) ⇒ Object
3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 |
# File 'lib/syntax_tree/node.rb', line 3187 def deconstruct_keys(keys) { receiver: receiver, operator: operator, message: , arguments: arguments, location: location, comments: comments } end |
#format(q) ⇒ Object
3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 |
# File 'lib/syntax_tree/node.rb', line 3198 def format(q) q.group do doc = q.nest(0) do q.format(receiver) q.format(CallOperatorFormatter.new(operator), stackable: false) q.format() end if arguments q.text(" ") q.nest(argument_alignment(q, doc)) { q.format(arguments) } end end end |
#pretty_print(q) ⇒ Object
3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 |
# File 'lib/syntax_tree/node.rb', line 3214 def pretty_print(q) q.group(2, "(", ")") do q.text("command_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
3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 |
# File 'lib/syntax_tree/node.rb', line 3236 def to_json(*opts) { type: :command_call, receiver: receiver, op: operator, message: , args: arguments, loc: location, cmts: comments }.to_json(*opts) end |