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

Constructor Details

#initialize(arguments:, location:, comments: []) ⇒ Next

Returns a new instance of Next.



7262
7263
7264
7265
7266
# File 'lib/syntax_tree/node.rb', line 7262

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

Instance Attribute Details

#argumentsObject (readonly)

Args

the arguments passed to the next keyword



7257
7258
7259
# File 'lib/syntax_tree/node.rb', line 7257

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



7260
7261
7262
# File 'lib/syntax_tree/node.rb', line 7260

def comments
  @comments
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



7268
7269
7270
# File 'lib/syntax_tree/node.rb', line 7268

def child_nodes
  [arguments]
end

#deconstruct_keys(keys) ⇒ Object



7274
7275
7276
# File 'lib/syntax_tree/node.rb', line 7274

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

#format(q) ⇒ Object



7278
7279
7280
# File 'lib/syntax_tree/node.rb', line 7278

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

#pretty_print(q) ⇒ Object



7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
# File 'lib/syntax_tree/node.rb', line 7282

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("next")

    q.breakable
    q.pp(arguments)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



7293
7294
7295
7296
7297
# File 'lib/syntax_tree/node.rb', line 7293

def to_json(*opts)
  { type: :next, args: arguments, loc: location, cmts: comments }.to_json(
    *opts
  )
end