Izyan jutt
Izyan jutt

Reputation: 1

i am getting error of ABC error from rubocop how i can remove it

def result_p3(high, low)
    arr_ind = []
    ((1..31).each { |n| arr_ind << n })
    (0..30).each do |i|
      puts " #{arr_ind[i]}" + " #{'+' * high[i].to_i} ".red + "#{high[i].to_i}C "
      puts " #{arr_ind[i]}" + " #{'+' * low[i].to_i} ".blue + "#{low[i].to_i}C "
    end
  end

Upvotes: 0

Views: 151

Answers (2)

phil pirozhkov
phil pirozhkov

Reputation: 4900

arr_ind is redundant, it contains numbers from 1 to 31 in it. For any value of x, arr_ind[x] == x + 1. Instead of #{arr_ind[i]}, you could just #{i + 1}. And of course, remove everything related to arr_ind.

Upvotes: 0

Todd A. Jacobs
Todd A. Jacobs

Reputation: 84343

RuboCop is pretty clear about what the problem is: your method is too large. You can:

  1. refactor your code so that it fits within your team's coding standards, which is the recommended approach;
  2. update your todo file so you don't see the error until you're ready to fix it; or
  3. disable the cop for this method, which is something you definitely shouldn't be doing if you don't understand why RuboCop is telling you that your code is not ideal.

RuboCop is a linter and style guide. It isn't always right, but in this case it is. Your method needs to be refactored, so either do that or postpone fixing it, but definitely treat it as a code smell.

Upvotes: 1

Related Questions