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.



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

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



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

def comments
  @comments
end

#nameObject (readonly)

nil | Ident

the name of the parameter



6990
6991
6992
# File 'lib/syntax_tree/node.rb', line 6990

def name
  @name
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



7001
7002
7003
# File 'lib/syntax_tree/node.rb', line 7001

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  [name]
end

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



7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
# File 'lib/syntax_tree/node.rb', line 7009

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



7022
7023
7024
# File 'lib/syntax_tree/node.rb', line 7022

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

#format(q) ⇒ Object



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

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