Class: SyntaxTree::Next

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

Overview

Next represents using the next keyword.

next

The next keyword can also optionally be called with an argument:

next value

next can even be called with multiple arguments, but only if parentheses are omitted, as in:

next first, second, third

If a single value is being given, parentheses can be used, as in:

next(value)

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(arguments:, location:) ⇒ Next

Returns a new instance of Next.



7823
7824
7825
7826
7827
# File 'lib/syntax_tree/node.rb', line 7823

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

Instance Attribute Details

#argumentsObject (readonly)

Args

the arguments passed to the next keyword



7818
7819
7820
# File 'lib/syntax_tree/node.rb', line 7818

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



7821
7822
7823
# File 'lib/syntax_tree/node.rb', line 7821

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



7858
7859
7860
# File 'lib/syntax_tree/node.rb', line 7858

def ===(other)
  other.is_a?(Next) && arguments === other.arguments
end

#accept(visitor) ⇒ Object



7829
7830
7831
# File 'lib/syntax_tree/node.rb', line 7829

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

#child_nodesObject Also known as: deconstruct



7833
7834
7835
# File 'lib/syntax_tree/node.rb', line 7833

def child_nodes
  [arguments]
end

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



7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
# File 'lib/syntax_tree/node.rb', line 7837

def copy(arguments: nil, location: nil)
  node =
    Next.new(
      arguments: arguments || self.arguments,
      location: location || self.location
    )

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

#deconstruct_keys(_keys) ⇒ Object



7850
7851
7852
# File 'lib/syntax_tree/node.rb', line 7850

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

#format(q) ⇒ Object



7854
7855
7856
# File 'lib/syntax_tree/node.rb', line 7854

def format(q)
  FlowControlFormatter.new("next", self).format(q)
end