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.



1334
1335
1336
1337
1338
# File 'lib/syntax_tree.rb', line 1334

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



1332
1333
1334
# File 'lib/syntax_tree.rb', line 1332

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



1329
1330
1331
# File 'lib/syntax_tree.rb', line 1329

def location
  @location
end

#valueObject (readonly)

String

the value of the operator



1326
1327
1328
# File 'lib/syntax_tree.rb', line 1326

def value
  @value
end

Instance Method Details

#child_nodesObject



1340
1341
1342
# File 'lib/syntax_tree.rb', line 1340

def child_nodes
  []
end

#format(q) ⇒ Object



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

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

#pretty_print(q) ⇒ Object



1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
# File 'lib/syntax_tree.rb', line 1348

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



1359
1360
1361
1362
1363
1364
1365
1366
# File 'lib/syntax_tree.rb', line 1359

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