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

Methods inherited from Node

#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(value:, location:) ⇒ ArgStar

Returns a new instance of ArgStar.



946
947
948
949
950
# File 'lib/syntax_tree/node.rb', line 946

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



944
945
946
# File 'lib/syntax_tree/node.rb', line 944

def comments
  @comments
end

#valueObject (readonly)

nil | Node

the expression being splatted



941
942
943
# File 'lib/syntax_tree/node.rb', line 941

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



982
983
984
# File 'lib/syntax_tree/node.rb', line 982

def ===(other)
  other.is_a?(ArgStar) && value === other.value
end

#accept(visitor) ⇒ Object



952
953
954
# File 'lib/syntax_tree/node.rb', line 952

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

#child_nodesObject Also known as: deconstruct



956
957
958
# File 'lib/syntax_tree/node.rb', line 956

def child_nodes
  [value]
end

#copy(value: nil, location: nil) ⇒ Object



960
961
962
963
964
965
966
967
968
969
# File 'lib/syntax_tree/node.rb', line 960

def copy(value: nil, location: nil)
  node =
    ArgStar.new(
      value: value || self.value,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



973
974
975
# File 'lib/syntax_tree/node.rb', line 973

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

#format(q) ⇒ Object



977
978
979
980
# File 'lib/syntax_tree/node.rb', line 977

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