Class: SyntaxTree::ArgStar

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

Star represents using a splat operator on an expression.

method(*arguments)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ ArgStar

Returns a new instance of ArgStar.



837
838
839
840
841
# File 'lib/syntax_tree/node.rb', line 837

def initialize(value:, location:, comments: [])
  @value = value
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



835
836
837
# File 'lib/syntax_tree/node.rb', line 835

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



832
833
834
# File 'lib/syntax_tree/node.rb', line 832

def location
  @location
end

#valueObject (readonly)

nil | untyped

the expression being splatted



829
830
831
# File 'lib/syntax_tree/node.rb', line 829

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



843
844
845
# File 'lib/syntax_tree/node.rb', line 843

def child_nodes
  [value]
end

#deconstruct_keys(keys) ⇒ Object



849
850
851
# File 'lib/syntax_tree/node.rb', line 849

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

#format(q) ⇒ Object



853
854
855
856
# File 'lib/syntax_tree/node.rb', line 853

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

#pretty_print(q) ⇒ Object



858
859
860
861
862
863
864
865
866
867
# File 'lib/syntax_tree/node.rb', line 858

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("arg_star")

    q.breakable
    q.pp(value)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



869
870
871
872
873
# File 'lib/syntax_tree/node.rb', line 869

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