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.



7157
7158
7159
7160
7161
# File 'lib/syntax_tree.rb', line 7157

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



7155
7156
7157
# File 'lib/syntax_tree.rb', line 7155

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7152
7153
7154
# File 'lib/syntax_tree.rb', line 7152

def location
  @location
end

#nameObject (readonly)

nil | Ident

the name of the parameter



7149
7150
7151
# File 'lib/syntax_tree.rb', line 7149

def name
  @name
end

Instance Method Details

#child_nodesObject



7163
7164
7165
# File 'lib/syntax_tree.rb', line 7163

def child_nodes
  [name]
end

#format(q) ⇒ Object



7167
7168
7169
7170
# File 'lib/syntax_tree.rb', line 7167

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

#pretty_print(q) ⇒ Object



7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
# File 'lib/syntax_tree.rb', line 7172

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



7183
7184
7185
7186
7187
7188
7189
7190
# File 'lib/syntax_tree.rb', line 7183

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