Parent

Methods

Files

Class/Module Index [+]

Quicksearch

RuboCop::Cop::Style::EvenOdd

This cop checks for places where Fixnum#even? or Fixnum#odd? should have been used.

@example

# bad
if x % 2 == 0

# good
if x.even?

Public Instance Methods

on_send(node) click to toggle source
# File lib/rubocop/cop/style/even_odd.rb, line 23
def on_send(node)
  receiver, method, args = *node

  return unless [:==, :!=].include?(method)
  return unless div_by_2?(receiver)

  if args == ZERO
    add_offense(node,
                :expression,
                method == :== ? MSG_EVEN : MSG_ODD)
  elsif args == ONE
    add_offense(node,
                :expression,
                method == :== ? MSG_ODD : MSG_EVEN)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.