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.



7528
7529
7530
7531
7532
# File 'lib/syntax_tree.rb', line 7528

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



7526
7527
7528
# File 'lib/syntax_tree.rb', line 7526

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7523
7524
7525
# File 'lib/syntax_tree.rb', line 7523

def location
  @location
end

#nameObject (readonly)

nil | Ident

the name of the parameter



7520
7521
7522
# File 'lib/syntax_tree.rb', line 7520

def name
  @name
end

Instance Method Details

#child_nodesObject



7534
7535
7536
# File 'lib/syntax_tree.rb', line 7534

def child_nodes
  [name]
end

#format(q) ⇒ Object



7538
7539
7540
7541
# File 'lib/syntax_tree.rb', line 7538

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

#pretty_print(q) ⇒ Object



7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
# File 'lib/syntax_tree.rb', line 7543

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



7554
7555
7556
7557
7558
7559
7560
7561
# File 'lib/syntax_tree.rb', line 7554

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