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.



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

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



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

def comments
  @comments
end

#valueObject (readonly)

nil | Node

the expression being splatted



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

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  [value]
end

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



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

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



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

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

#format(q) ⇒ Object



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

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