Class: SyntaxTree::Call
- Inherits:
-
Object
- Object
- SyntaxTree::Call
- Defined in:
- lib/syntax_tree.rb
Overview
Call represents a method call.
receiver.
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
- nil | ArgParen | Args
-
the arguments to the method call.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#message ⇒ Object
readonly
- :call | Backtick | Const | Ident | Op
-
the message being sent.
-
#operator ⇒ Object
readonly
- :“::” | Op | Period
-
the operator being used to send the message.
-
#receiver ⇒ Object
readonly
- untyped
-
the receiver of the method call.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(receiver:, operator:, message:, arguments:, location:, comments: []) ⇒ Call
constructor
A new instance of Call.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(receiver:, operator:, message:, arguments:, location:, comments: []) ⇒ Call
Returns a new instance of Call.
3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 |
# File 'lib/syntax_tree.rb', line 3183 def initialize( receiver:, operator:, message:, arguments:, location:, comments: [] ) @receiver = receiver @operator = operator = @arguments = arguments @location = location @comments = comments end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
- nil | ArgParen | Args
-
the arguments to the method call
3175 3176 3177 |
# File 'lib/syntax_tree.rb', line 3175 def arguments @arguments end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3181 3182 3183 |
# File 'lib/syntax_tree.rb', line 3181 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
3178 3179 3180 |
# File 'lib/syntax_tree.rb', line 3178 def location @location end |
#message ⇒ Object (readonly)
- :call | Backtick | Const | Ident | Op
-
the message being sent
3172 3173 3174 |
# File 'lib/syntax_tree.rb', line 3172 def end |
#operator ⇒ Object (readonly)
- :“::” | Op | Period
-
the operator being used to send the message
3169 3170 3171 |
# File 'lib/syntax_tree.rb', line 3169 def operator @operator end |
#receiver ⇒ Object (readonly)
- untyped
-
the receiver of the method call
3166 3167 3168 |
# File 'lib/syntax_tree.rb', line 3166 def receiver @receiver end |
Instance Method Details
#child_nodes ⇒ Object
3199 3200 3201 3202 3203 3204 3205 3206 |
# File 'lib/syntax_tree.rb', line 3199 def child_nodes [ receiver, (operator if operator != :"::"), ( if != :call), arguments ] end |
#format(q) ⇒ Object
3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 |
# File 'lib/syntax_tree.rb', line 3208 def format(q) call_operator = CallOperatorFormatter.new(operator) q.group do q.format(receiver) # If there are trailing comments on the call operator, then we need to # use the trailing form as opposed to the leading form. q.format(call_operator) if call_operator.comments.any? q.group do q.indent do if receiver.comments.any? || call_operator.comments.any? q.breakable(force: true) end q.format(call_operator) if call_operator.comments.empty? q.format() if != :call end q.format(arguments) if arguments end end end |
#pretty_print(q) ⇒ Object
3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 |
# File 'lib/syntax_tree.rb', line 3232 def pretty_print(q) q.group(2, "(", ")") do q.text("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
3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 |
# File 'lib/syntax_tree.rb', line 3254 def to_json(*opts) { type: :call, receiver: receiver, op: operator, message: , args: arguments, loc: location, cmts: comments }.to_json(*opts) end |