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.



7733
7734
7735
7736
7737
# File 'lib/syntax_tree.rb', line 7733

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



7731
7732
7733
# File 'lib/syntax_tree.rb', line 7731

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7728
7729
7730
# File 'lib/syntax_tree.rb', line 7728

def location
  @location
end

#nameObject (readonly)

nil | Ident

the name of the parameter



7725
7726
7727
# File 'lib/syntax_tree.rb', line 7725

def name
  @name
end

Instance Method Details

#child_nodesObject



7739
7740
7741
# File 'lib/syntax_tree.rb', line 7739

def child_nodes
  [name]
end

#format(q) ⇒ Object



7743
7744
7745
7746
# File 'lib/syntax_tree.rb', line 7743

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

#pretty_print(q) ⇒ Object



7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
# File 'lib/syntax_tree.rb', line 7748

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



7759
7760
7761
7762
7763
7764
7765
7766
# File 'lib/syntax_tree.rb', line 7759

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