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.



9961
9962
9963
9964
9965
# File 'lib/syntax_tree.rb', line 9961

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



9959
9960
9961
# File 'lib/syntax_tree.rb', line 9959

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



9956
9957
9958
# File 'lib/syntax_tree.rb', line 9956

def location
  @location
end

#nameObject (readonly)

nil | Ident

the name of the parameter



9953
9954
9955
# File 'lib/syntax_tree.rb', line 9953

def name
  @name
end

Instance Method Details

#child_nodesObject



9967
9968
9969
# File 'lib/syntax_tree.rb', line 9967

def child_nodes
  [name]
end

#format(q) ⇒ Object



9971
9972
9973
9974
# File 'lib/syntax_tree.rb', line 9971

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

#pretty_print(q) ⇒ Object



9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
# File 'lib/syntax_tree.rb', line 9976

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



9987
9988
9989
9990
9991
# File 'lib/syntax_tree.rb', line 9987

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