Class: SyntaxTree::RestParam

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

RestParam represents defining a parameter in a method definition that accepts all remaining positional parameters.

def method(*rest) end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of RestParam.



10415
10416
10417
10418
10419
# File 'lib/syntax_tree.rb', line 10415

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



10413
10414
10415
# File 'lib/syntax_tree.rb', line 10413

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



10410
10411
10412
# File 'lib/syntax_tree.rb', line 10410

def location
  @location
end

#nameObject (readonly)

nil | Ident

the name of the parameter



10407
10408
10409
# File 'lib/syntax_tree.rb', line 10407

def name
  @name
end

Instance Method Details

#child_nodesObject



10421
10422
10423
# File 'lib/syntax_tree.rb', line 10421

def child_nodes
  [name]
end

#format(q) ⇒ Object



10425
10426
10427
10428
# File 'lib/syntax_tree.rb', line 10425

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

#pretty_print(q) ⇒ Object



10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
# File 'lib/syntax_tree.rb', line 10430

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

    q.breakable
    q.pp(name)

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

#to_json(*opts) ⇒ Object



10441
10442
10443
10444
10445
# File 'lib/syntax_tree.rb', line 10441

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