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.



10491
10492
10493
10494
10495
# File 'lib/syntax_tree.rb', line 10491

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



10489
10490
10491
# File 'lib/syntax_tree.rb', line 10489

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



10486
10487
10488
# File 'lib/syntax_tree.rb', line 10486

def location
  @location
end

#nameObject (readonly)

nil | Ident

the name of the parameter



10483
10484
10485
# File 'lib/syntax_tree.rb', line 10483

def name
  @name
end

Instance Method Details

#child_nodesObject



10497
10498
10499
# File 'lib/syntax_tree.rb', line 10497

def child_nodes
  [name]
end

#format(q) ⇒ Object



10501
10502
10503
10504
# File 'lib/syntax_tree.rb', line 10501

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

#pretty_print(q) ⇒ Object



10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
# File 'lib/syntax_tree.rb', line 10506

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



10517
10518
10519
10520
10521
# File 'lib/syntax_tree.rb', line 10517

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