Bird
0
0

How can you disable a specific Rubocop cop for a single line of Ruby code?

hard📝 Application Q9 of 15
Ruby - Ecosystem and Best Practices

How can you disable a specific Rubocop cop for a single line of Ruby code?

some_code_here # ???
A# rubocop:skip CopName
B# rubocop:disable CopName
C# rubocop:ignore CopName
D# rubocop:enable CopName
Step-by-Step Solution
Solution:
  1. Step 1: Recall inline disabling syntax

    To disable a cop for a single line, use # rubocop:disable CopName at the end of that line.
  2. Step 2: Differentiate from enable and other keywords

    enable re-enables a cop, while ignore and skip are not valid Rubocop directives.
  3. Final Answer:

    # rubocop:disable CopName -> Option B
  4. Quick Check:

    Disable cop inline with rubocop:disable [OK]
Quick Trick: Use '# rubocop:disable CopName' to skip one line [OK]
Common Mistakes:
  • Using rubocop:enable to disable
  • Using rubocop:ignore or rubocop:skip (invalid)
  • Placing directive on wrong line

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes