Class: SyntaxTree::ArgsForward

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

ArgsForward represents forwarding all kinds of arguments onto another method call.

def request(method, path, **headers, &block); end

def get(...)
  request(:GET, ...)
end

def post(...)
  request(:POST, ...)
end

In the example above, both the get and post methods are forwarding all of their arguments (positional, keyword, and block) on to the request method. The ArgsForward node appears in both the caller (the request method calls) and the callee (the get and post definitions).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ ArgsForward

Returns a new instance of ArgsForward.



1283
1284
1285
1286
1287
# File 'lib/syntax_tree.rb', line 1283

def initialize(value:, location:, comments: [])
  @value = value
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1281
1282
1283
# File 'lib/syntax_tree.rb', line 1281

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



1278
1279
1280
# File 'lib/syntax_tree.rb', line 1278

def location
  @location
end

#valueObject (readonly)

String

the value of the operator



1275
1276
1277
# File 'lib/syntax_tree.rb', line 1275

def value
  @value
end

Instance Method Details

#child_nodesObject



1289
1290
1291
# File 'lib/syntax_tree.rb', line 1289

def child_nodes
  []
end

#format(q) ⇒ Object



1293
1294
1295
# File 'lib/syntax_tree.rb', line 1293

def format(q)
  q.text(value)
end

#pretty_print(q) ⇒ Object



1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
# File 'lib/syntax_tree.rb', line 1297

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("args_forward")

    q.breakable
    q.pp(value)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



1308
1309
1310
1311
1312
1313
1314
1315
# File 'lib/syntax_tree.rb', line 1308

def to_json(*opts)
  {
    type: :args_forward,
    value: value,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end