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.



6940
6941
6942
6943
6944
# File 'lib/syntax_tree/node.rb', line 6940

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6938
6939
6940
# File 'lib/syntax_tree/node.rb', line 6938

def comments
  @comments
end

#nameObject (readonly)

nil | Ident

the name of the parameter



6935
6936
6937
# File 'lib/syntax_tree/node.rb', line 6935

def name
  @name
end

Instance Method Details

#===(other) ⇒ Object



6976
6977
6978
# File 'lib/syntax_tree/node.rb', line 6976

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

#accept(visitor) ⇒ Object



6946
6947
6948
# File 'lib/syntax_tree/node.rb', line 6946

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

#child_nodesObject Also known as: deconstruct



6950
6951
6952
# File 'lib/syntax_tree/node.rb', line 6950

def child_nodes
  [name]
end

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



6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
# File 'lib/syntax_tree/node.rb', line 6954

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



6967
6968
6969
# File 'lib/syntax_tree/node.rb', line 6967

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

#format(q) ⇒ Object



6971
6972
6973
6974
# File 'lib/syntax_tree/node.rb', line 6971

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