Class: SyntaxTree::Next

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Next.



8617
8618
8619
8620
8621
# File 'lib/syntax_tree.rb', line 8617

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



8609
8610
8611
# File 'lib/syntax_tree.rb', line 8609

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8615
8616
8617
# File 'lib/syntax_tree.rb', line 8615

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



8612
8613
8614
# File 'lib/syntax_tree.rb', line 8612

def location
  @location
end

Instance Method Details

#child_nodesObject



8623
8624
8625
# File 'lib/syntax_tree.rb', line 8623

def child_nodes
  [arguments]
end

#format(q) ⇒ Object



8627
8628
8629
# File 'lib/syntax_tree.rb', line 8627

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

#pretty_print(q) ⇒ Object



8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
# File 'lib/syntax_tree.rb', line 8631

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



8642
8643
8644
8645
8646
# File 'lib/syntax_tree.rb', line 8642

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