Class: SyntaxTree::KwRestParam

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.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.



7601
7602
7603
7604
7605
# File 'lib/syntax_tree.rb', line 7601

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



7599
7600
7601
# File 'lib/syntax_tree.rb', line 7599

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7596
7597
7598
# File 'lib/syntax_tree.rb', line 7596

def location
  @location
end

#nameObject (readonly)

nil | Ident

the name of the parameter



7593
7594
7595
# File 'lib/syntax_tree.rb', line 7593

def name
  @name
end

Instance Method Details

#child_nodesObject



7607
7608
7609
# File 'lib/syntax_tree.rb', line 7607

def child_nodes
  [name]
end

#format(q) ⇒ Object



7611
7612
7613
7614
# File 'lib/syntax_tree.rb', line 7611

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

#pretty_print(q) ⇒ Object



7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
# File 'lib/syntax_tree.rb', line 7616

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



7627
7628
7629
7630
7631
7632
7633
7634
# File 'lib/syntax_tree.rb', line 7627

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