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, #pretty_print, #to_json

Constructor Details

#initialize(location:) ⇒ ArgsForward



997
998
999
1000
# File 'lib/syntax_tree/node.rb', line 997

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



995
996
997
# File 'lib/syntax_tree/node.rb', line 995

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



1027
1028
1029
# File 'lib/syntax_tree/node.rb', line 1027

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

#accept(visitor) ⇒ Object



1002
1003
1004
# File 'lib/syntax_tree/node.rb', line 1002

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

#arityObject



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

def arity
  Float::INFINITY
end

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  []
end

#copy(location: nil) ⇒ Object



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

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

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

#deconstruct_keys(_keys) ⇒ Object



1019
1020
1021
# File 'lib/syntax_tree/node.rb', line 1019

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

#format(q) ⇒ Object



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

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