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.



1353
1354
1355
1356
1357
# File 'lib/syntax_tree.rb', line 1353

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



1351
1352
1353
# File 'lib/syntax_tree.rb', line 1351

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



1348
1349
1350
# File 'lib/syntax_tree.rb', line 1348

def location
  @location
end

#valueObject (readonly)

String

the value of the operator



1345
1346
1347
# File 'lib/syntax_tree.rb', line 1345

def value
  @value
end

Instance Method Details

#child_nodesObject



1359
1360
1361
# File 'lib/syntax_tree.rb', line 1359

def child_nodes
  []
end

#format(q) ⇒ Object



1363
1364
1365
# File 'lib/syntax_tree.rb', line 1363

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

#pretty_print(q) ⇒ Object



1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
# File 'lib/syntax_tree.rb', line 1367

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



1378
1379
1380
1381
1382
1383
1384
1385
# File 'lib/syntax_tree.rb', line 1378

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