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.



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

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



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

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



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

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

#arityObject



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

def arity
  Float::INFINITY
end

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  []
end

#copy(location: nil) ⇒ Object



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

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

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

#deconstruct_keys(_keys) ⇒ Object



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

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

#format(q) ⇒ Object



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

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