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

Returns a new instance of ArgsForward.



978
979
980
981
# File 'lib/syntax_tree/node.rb', line 978

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



976
977
978
# File 'lib/syntax_tree/node.rb', line 976

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



983
984
985
# File 'lib/syntax_tree/node.rb', line 983

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

#child_nodesObject Also known as: deconstruct



987
988
989
# File 'lib/syntax_tree/node.rb', line 987

def child_nodes
  []
end

#copy(location: nil) ⇒ Object



991
992
993
994
995
996
# File 'lib/syntax_tree/node.rb', line 991

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

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

#deconstruct_keys(_keys) ⇒ Object



1000
1001
1002
# File 'lib/syntax_tree/node.rb', line 1000

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

#format(q) ⇒ Object



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

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