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

#construct_keys, #pretty_print, #to_json

Constructor Details

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

Returns a new instance of RestParam.



7764
7765
7766
7767
7768
# File 'lib/syntax_tree/node.rb', line 7764

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



7762
7763
7764
# File 'lib/syntax_tree/node.rb', line 7762

def comments
  @comments
end

#nameObject (readonly)

nil | Ident

the name of the parameter



7759
7760
7761
# File 'lib/syntax_tree/node.rb', line 7759

def name
  @name
end

Instance Method Details

#accept(visitor) ⇒ Object



7770
7771
7772
# File 'lib/syntax_tree/node.rb', line 7770

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

#child_nodesObject Also known as: deconstruct



7774
7775
7776
# File 'lib/syntax_tree/node.rb', line 7774

def child_nodes
  [name]
end

#deconstruct_keys(_keys) ⇒ Object



7780
7781
7782
# File 'lib/syntax_tree/node.rb', line 7780

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

#format(q) ⇒ Object



7784
7785
7786
7787
# File 'lib/syntax_tree/node.rb', line 7784

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