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

Instance Method Summary collapse

Constructor Details

#initialize(name:, location:, comments: []) ⇒ KwRestParam

Returns a new instance of KwRestParam.



6707
6708
6709
6710
6711
# File 'lib/syntax_tree/node.rb', line 6707

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

Instance Attribute Details

#commentsObject (readonly)

[Array[ Comment | EmbDoc ]] the comments attached to this node



6705
6706
6707
# File 'lib/syntax_tree/node.rb', line 6705

def comments
  @comments
end

#locationObject (readonly)

[Location] the location of this node



6702
6703
6704
# File 'lib/syntax_tree/node.rb', line 6702

def location
  @location
end

#nameObject (readonly)

[nil | Ident] the name of the parameter



6699
6700
6701
# File 'lib/syntax_tree/node.rb', line 6699

def name
  @name
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



6713
6714
6715
# File 'lib/syntax_tree/node.rb', line 6713

def child_nodes
  [name]
end

#deconstruct_keys(keys) ⇒ Object



6719
6720
6721
# File 'lib/syntax_tree/node.rb', line 6719

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

#format(q) ⇒ Object



6723
6724
6725
6726
# File 'lib/syntax_tree/node.rb', line 6723

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

#pretty_print(q) ⇒ Object



6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
# File 'lib/syntax_tree/node.rb', line 6728

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("kwrest_param")

    q.breakable
    q.pp(name)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



6739
6740
6741
6742
6743
6744
6745
6746
# File 'lib/syntax_tree/node.rb', line 6739

def to_json(*opts)
  {
    type: :kwrest_param,
    name: name,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end