Class: SyntaxTree::ArgsForward

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.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

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(location:) ⇒ ArgsForward

Returns a new instance of ArgsForward.



1008
1009
1010
1011
# File 'lib/syntax_tree/node.rb', line 1008

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1006
1007
1008
# File 'lib/syntax_tree/node.rb', line 1006

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



1038
1039
1040
# File 'lib/syntax_tree/node.rb', line 1038

def ===(other)
  other.is_a?(ArgsForward)
end

#accept(visitor) ⇒ Object



1013
1014
1015
# File 'lib/syntax_tree/node.rb', line 1013

def accept(visitor)
  visitor.visit_args_forward(self)
end

#arityObject



1042
1043
1044
# File 'lib/syntax_tree/node.rb', line 1042

def arity
  Float::INFINITY
end

#child_nodesObject Also known as: deconstruct



1017
1018
1019
# File 'lib/syntax_tree/node.rb', line 1017

def child_nodes
  []
end

#copy(location: nil) ⇒ Object



1021
1022
1023
1024
1025
1026
# File 'lib/syntax_tree/node.rb', line 1021

def copy(location: nil)
  node = ArgsForward.new(location: location || self.location)

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



1030
1031
1032
# File 'lib/syntax_tree/node.rb', line 1030

def deconstruct_keys(_keys)
  { location: location, comments: comments }
end

#format(q) ⇒ Object



1034
1035
1036
# File 'lib/syntax_tree/node.rb', line 1034

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