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

Attributes inherited from Node

#location

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ArgStar.



807
808
809
810
811
# File 'lib/syntax_tree/node.rb', line 807

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



805
806
807
# File 'lib/syntax_tree/node.rb', line 805

def comments
  @comments
end

#valueObject (readonly)

nil | untyped

the expression being splatted



802
803
804
# File 'lib/syntax_tree/node.rb', line 802

def value
  @value
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



813
814
815
# File 'lib/syntax_tree/node.rb', line 813

def child_nodes
  [value]
end

#deconstruct_keys(keys) ⇒ Object



819
820
821
# File 'lib/syntax_tree/node.rb', line 819

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

#format(q) ⇒ Object



823
824
825
826
# File 'lib/syntax_tree/node.rb', line 823

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

#pretty_print(q) ⇒ Object



828
829
830
831
832
833
834
835
836
837
# File 'lib/syntax_tree/node.rb', line 828

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



839
840
841
842
843
# File 'lib/syntax_tree/node.rb', line 839

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