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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of RestParam.



9056
9057
9058
9059
9060
# File 'lib/syntax_tree/node.rb', line 9056

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



9054
9055
9056
# File 'lib/syntax_tree/node.rb', line 9054

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



9051
9052
9053
# File 'lib/syntax_tree/node.rb', line 9051

def location
  @location
end

#nameObject (readonly)

nil | Ident

the name of the parameter



9048
9049
9050
# File 'lib/syntax_tree/node.rb', line 9048

def name
  @name
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



9062
9063
9064
# File 'lib/syntax_tree/node.rb', line 9062

def child_nodes
  [name]
end

#deconstruct_keys(keys) ⇒ Object



9068
9069
9070
# File 'lib/syntax_tree/node.rb', line 9068

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

#format(q) ⇒ Object



9072
9073
9074
9075
# File 'lib/syntax_tree/node.rb', line 9072

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

#pretty_print(q) ⇒ Object



9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
# File 'lib/syntax_tree/node.rb', line 9077

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



9088
9089
9090
9091
9092
# File 'lib/syntax_tree/node.rb', line 9088

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