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.



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

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6969
6970
6971
# File 'lib/syntax_tree/node.rb', line 6969

def comments
  @comments
end

#nameObject (readonly)

nil | Ident

the name of the parameter



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

def name
  @name
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



6981
6982
6983
# File 'lib/syntax_tree/node.rb', line 6981

def child_nodes
  [name]
end

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



6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
# File 'lib/syntax_tree/node.rb', line 6985

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



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

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

#format(q) ⇒ Object



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

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