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

Constructor Details

#initialize(name:, location:) ⇒ KwRestParam

Returns a new instance of KwRestParam.



6998
6999
7000
7001
7002
# File 'lib/syntax_tree/node.rb', line 6998

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6996
6997
6998
# File 'lib/syntax_tree/node.rb', line 6996

def comments
  @comments
end

#nameObject (readonly)

nil | Ident

the name of the parameter



6993
6994
6995
# File 'lib/syntax_tree/node.rb', line 6993

def name
  @name
end

Instance Method Details

#===(other) ⇒ Object



7034
7035
7036
# File 'lib/syntax_tree/node.rb', line 7034

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

#accept(visitor) ⇒ Object



7004
7005
7006
# File 'lib/syntax_tree/node.rb', line 7004

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

#child_nodesObject Also known as: deconstruct



7008
7009
7010
# File 'lib/syntax_tree/node.rb', line 7008

def child_nodes
  [name]
end

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



7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
# File 'lib/syntax_tree/node.rb', line 7012

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



7025
7026
7027
# File 'lib/syntax_tree/node.rb', line 7025

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

#format(q) ⇒ Object



7029
7030
7031
7032
# File 'lib/syntax_tree/node.rb', line 7029

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