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

Constructor Details

#initialize(value:, location:, comments: []) ⇒ ArgsForward

Returns a new instance of ArgsForward.



870
871
872
873
874
# File 'lib/syntax_tree/node.rb', line 870

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



868
869
870
# File 'lib/syntax_tree/node.rb', line 868

def comments
  @comments
end

#valueObject (readonly)

String

the value of the operator



865
866
867
# File 'lib/syntax_tree/node.rb', line 865

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



876
877
878
# File 'lib/syntax_tree/node.rb', line 876

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



882
883
884
# File 'lib/syntax_tree/node.rb', line 882

def deconstruct_keys(keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



886
887
888
# File 'lib/syntax_tree/node.rb', line 886

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

#pretty_print(q) ⇒ Object



890
891
892
893
894
895
896
897
898
899
# File 'lib/syntax_tree/node.rb', line 890

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



901
902
903
904
905
906
907
908
# File 'lib/syntax_tree/node.rb', line 901

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