Class: SyntaxTree::RestParam

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.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

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

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

Returns a new instance of RestParam.



7588
7589
7590
7591
7592
# File 'lib/syntax_tree/node.rb', line 7588

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



7586
7587
7588
# File 'lib/syntax_tree/node.rb', line 7586

def comments
  @comments
end

#nameObject (readonly)

nil | Ident

the name of the parameter



7583
7584
7585
# File 'lib/syntax_tree/node.rb', line 7583

def name
  @name
end

Instance Method Details

#accept(visitor) ⇒ Object



7594
7595
7596
# File 'lib/syntax_tree/node.rb', line 7594

def accept(visitor)
  visitor.visit_rest_param(self)
end

#child_nodesObject Also known as: deconstruct



7598
7599
7600
# File 'lib/syntax_tree/node.rb', line 7598

def child_nodes
  [name]
end

#deconstruct_keys(keys) ⇒ Object



7604
7605
7606
# File 'lib/syntax_tree/node.rb', line 7604

def deconstruct_keys(keys)
  { name: name, location: location, comments: comments }
end

#format(q) ⇒ Object



7608
7609
7610
7611
# File 'lib/syntax_tree/node.rb', line 7608

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