Parent

Files

Class/Module Index [+]

Quicksearch

RuboCop::Cop::Style::Next

Use `next` to skip iteration instead of a condition at the end.

@example

# bad
[1, 2].each do |a|
  if a == 1 do
    puts a
  end
end

# good
[1, 2].each do |a|
  next unless a == 1
  puts a
end

Constants

METHODS
MSG

Public Instance Methods

on_block(node) click to toggle source
# File lib/rubocop/cop/style/next.rb, line 29
def on_block(node)
  method, _, body = *node
  return unless method.type == :send
  return if body.nil?

  _, method_name = *method
  return unless method?(method_name)
  return unless ends_with_condition?(body)

  add_offense(method, :selector, MSG)
end
on_for(node) click to toggle source
# File lib/rubocop/cop/style/next.rb, line 49
def on_for(node)
  _, _, body = *node
  return unless ends_with_condition?(body)

  add_offense(node, :keyword, MSG)
end
on_until(node) click to toggle source
Alias for: on_while
on_while(node) click to toggle source
# File lib/rubocop/cop/style/next.rb, line 41
def on_while(node)
  _, body = *node
  return unless ends_with_condition?(body)

  add_offense(node, :keyword, MSG)
end
Also aliased as: on_until

[Validate]

Generated with the Darkfish Rdoc Generator 2.