Deep Nesting (ARCH6184)
هذا المحتوى غير متوفر بلغتك بعد.
Key ruby.quality.deep-nesting · Severity warning · Category quality
if/while/begin blocks nested beyond the threshold produce hard-to-read, hard-to-trace flow and can usually be fixed with early returns or extraction.
Incorrect
Section titled “Incorrect”def grade(user) if user if user.active? if user.score > 50 return "pass" end end end "fail"endCorrect
Section titled “Correct”def grade(user) return "fail" unless user&.active? return "fail" unless user.score > 50 "pass"endReturn early with guard clauses or extract nested blocks into separate methods to flatten the depth.