Style & Conventions Quiz
Validate your understanding of the Ruby style guide, idiomatic patterns, RuboCop, and documentation expectations used across RubyDev. Each question includes an answer and explanation—treat it like a lightweight code review exercise.
Instructions: Review each scenario, pick the most accurate statement, then compare with the answer block. Aim to reason about *why* an option is correct—style decisions should feel deliberate.
1. Guard Clauses
Which snippet best follows the Ruby style guide for guarding invalid state?
Answer: B — the guard clause raises early, keeps the happy path left-aligned, and uses a descriptive exception.
2. Naming Conventions
Which pairing follows Rails loading conventions without additional configuration?
Answer: C — snake_case file names match CamelCase constants; nested directories are only required for namespaced classes.
3. RuboCop Usage
You need to ignore a cop for a single method because an upstream library requires it. What is the recommended approach?
Answer: C — scope the disable to the minimal block and explain why, keeping the global configuration trustworthy.
4. YARD Docs
Which annotation set fully documents a public method that raises an error?
Answer: C — include type information, return value, and documented exceptions for accurate generated docs.
5. Naming Edge Cases
You introduce a background job that checks expired trials. Which combination best matches conventions?
Answer: B — jobs end with `Job`, live in `app/jobs`, and the file name mirrors the class with snake_case.
Level Up
- Pair this quiz with `bundle exec rubocop --auto-gen-config` to see which cops your module violates.
- Annotate a new service with YARD and regenerate docs to ensure zero undocumented public methods.
- Refine `AGENTS.md` whenever the team agrees on a new exception to the style guide.