Class: SyntaxTree::KwRestParam

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

KwRestParam represents defining a parameter in a method definition that accepts all remaining keyword parameters.

def method(**kwargs) end

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(name:, location:) ⇒ KwRestParam

Returns a new instance of KwRestParam.



6880
6881
6882
6883
6884
# File 'lib/syntax_tree/node.rb', line 6880

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6878
6879
6880
# File 'lib/syntax_tree/node.rb', line 6878

def comments
  @comments
end

#nameObject (readonly)

nil | Ident

the name of the parameter



6875
6876
6877
# File 'lib/syntax_tree/node.rb', line 6875

def name
  @name
end

Instance Method Details

#===(other) ⇒ Object



6916
6917
6918
# File 'lib/syntax_tree/node.rb', line 6916

def ===(other)
  other.is_a?(KwRestParam) && name === other.name
end

#accept(visitor) ⇒ Object



6886
6887
6888
# File 'lib/syntax_tree/node.rb', line 6886

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

#child_nodesObject Also known as: deconstruct



6890
6891
6892
# File 'lib/syntax_tree/node.rb', line 6890

def child_nodes
  [name]
end

#copy(name: nil, location: nil) ⇒ Object



6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
# File 'lib/syntax_tree/node.rb', line 6894

def copy(name: nil, location: nil)
  node =
    KwRestParam.new(
      name: name || self.name,
      location: location || self.location
    )

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

#deconstruct_keys(_keys) ⇒ Object



6907
6908
6909
# File 'lib/syntax_tree/node.rb', line 6907

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

#format(q) ⇒ Object



6911
6912
6913
6914
# File 'lib/syntax_tree/node.rb', line 6911

def format(q)
  q.text("**")
  q.format(name) if name
end