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, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(arguments:, location:) ⇒ Next

Returns a new instance of Next.



7899
7900
7901
7902
7903
# File 'lib/syntax_tree/node.rb', line 7899

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

Instance Attribute Details

#argumentsObject (readonly)

Args

the arguments passed to the next keyword



7894
7895
7896
# File 'lib/syntax_tree/node.rb', line 7894

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



7897
7898
7899
# File 'lib/syntax_tree/node.rb', line 7897

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



7934
7935
7936
# File 'lib/syntax_tree/node.rb', line 7934

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

#accept(visitor) ⇒ Object



7905
7906
7907
# File 'lib/syntax_tree/node.rb', line 7905

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

#child_nodesObject Also known as: deconstruct



7909
7910
7911
# File 'lib/syntax_tree/node.rb', line 7909

def child_nodes
  [arguments]
end

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



7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
# File 'lib/syntax_tree/node.rb', line 7913

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



7926
7927
7928
# File 'lib/syntax_tree/node.rb', line 7926

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

#format(q) ⇒ Object



7930
7931
7932
# File 'lib/syntax_tree/node.rb', line 7930

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