Class: SyntaxTree::Args

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

Overview

Args represents a list of arguments being passed to a method call or array literal.

method(first, second, third)

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #pretty_print, #to_json

Constructor Details

#initialize(parts:, location:) ⇒ Args

Returns a new instance of Args.



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

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



811
812
813
# File 'lib/syntax_tree/node.rb', line 811

def comments
  @comments
end

#partsObject (readonly)

Array[ untyped ]

the arguments that this node wraps



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

def parts
  @parts
end

Instance Method Details

#===(other) ⇒ Object



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

def ===(other)
  other.is_a?(Args) && ArrayMatch.call(parts, other.parts)
end

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  parts
end

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



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

def copy(parts: nil, location: nil)
  node =
    Args.new(
      parts: parts || self.parts,
      location: location || self.location
    )

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

#deconstruct_keys(_keys) ⇒ Object



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

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

#format(q) ⇒ Object



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

def format(q)
  q.seplist(parts) { |part| q.format(part) }
end