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.



8064
8065
8066
8067
8068
# File 'lib/syntax_tree/node.rb', line 8064

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



8062
8063
8064
# File 'lib/syntax_tree/node.rb', line 8062

def comments
  @comments
end

#nameObject (readonly)

nil | Ident

the name of the parameter



8059
8060
8061
# File 'lib/syntax_tree/node.rb', line 8059

def name
  @name
end

Instance Method Details

#accept(visitor) ⇒ Object



8070
8071
8072
# File 'lib/syntax_tree/node.rb', line 8070

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

#child_nodesObject Also known as: deconstruct



8074
8075
8076
# File 'lib/syntax_tree/node.rb', line 8074

def child_nodes
  [name]
end

#deconstruct_keys(_keys) ⇒ Object



8080
8081
8082
# File 'lib/syntax_tree/node.rb', line 8080

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

#format(q) ⇒ Object



8084
8085
8086
8087
# File 'lib/syntax_tree/node.rb', line 8084

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