skills/sandi-metz-rules/SKILL.md
This skill should be used when users request code review, refactoring, or code quality improvements for Ruby codebases. Apply Sandi Metz's four rules for writing maintainable object-oriented code - classes under 100 lines, methods under 5 lines, no more than 4 parameters, and controllers instantiate only one object. Use when users mention "Sandi Metz", "code quality", "refactoring", or when reviewing Ruby code for maintainability.
npx skillsauth add lucianghinda/superpowers-ruby sandi-metz-rulesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill helps apply Sandi Metz's four rules for writing maintainable object-oriented code to Ruby codebases. These rules are heuristics that encourage good design practices, making code easier to understand, test, and maintain.
Apply this skill when:
When reviewing code against Sandi Metz's rules:
Read the reference document: First, load the detailed rules documentation:
Read references/rules.md
Measure accurately:
end statements)end statements)&block)Identify violations: Scan the codebase for violations of each rule. Use grep or file searching to find classes and methods, then analyze them systematically.
Not all violations are equal:
High priority:
Medium priority:
Low priority:
For each violation, provide concrete refactoring strategies:
Long classes:
Long methods:
Too many parameters:
Fat controllers:
When suggesting refactorings:
Remember that rules can be broken with good reason:
Always note when a violation might be acceptable and explain why.
When reviewing an entire codebase:
When reviewing a specific file:
When actively refactoring code:
Use these precise counting rules to ensure consistency:
Class lines:
class MyClass # Don't count
def method # Count: 1
body # Count: 2
end # Don't count
end # Don't count
Method lines:
def my_method # Don't count
line_1 # Count: 1
line_2 # Count: 2
# Don't count (blank line)
# comment # Don't count
line_3 # Count: 3
end # Don't count
Parameters:
def method(a, b, c, d) # 4 parameters - OK
def method(a, b, c, d, e) # 5 parameters - Violation
def method(a:, b:, c:, d:) # 4 parameters - OK
def method(a, b = nil, c = {}) # 3 parameters - OK (defaults still count)
def method(a, *rest) # 2 parameters - OK
def method(a, &block) # 1 parameter (blocks don't count)
Suggest using static analysis tools to enforce these rules:
Metrics/MethodLength, Metrics/ClassLength, Metrics/ParameterListsExample RuboCop configuration:
Metrics/ClassLength:
Max: 100
Metrics/MethodLength:
Max: 5
Metrics/ParameterLists:
Max: 4
MaxOptionalParameters: 3
This skill includes a comprehensive reference document with:
Load this reference when doing detailed code analysis or explaining refactoring approaches:
Read references/rules.md
development
Use when writing, reviewing, or debugging pure Ruby code — idiomatic patterns, modern 3.x+ features (pattern matching, Data.define, endless methods), error handling conventions (raise vs fail, result objects), memoization, and performance idioms. For Rails use rails-guides. For testing use minitest. For code style use sandi-metz-rules.
testing
Official Rails documentation. Use when asked about any Rails-specific topic including ActiveRecord, routing, controllers, views, mailers, jobs, Action Cable, Action Text, Active Storage, migrations, validations, callbacks, associations, caching, security, or internals.
tools
--- name: ruby-upgrade description: Use when upgrading the Ruby interpreter version of a Bundler/Rails app — especially "upgrade to Ruby 4", "bump Ruby to 4.0", "audit Ruby 4 compatibility", "what breaks on Ruby 4", or a specific target like "Ruby 4.0.5". Triggers on Ruby-major risk symptoms: CGI.parse/CGI::Cookie removal, Net::HTTP implicit Content-Type dropped, demoted default gems (ostruct/logger/benchmark/irb), SortedSet, Set#inspect changes, native-extension recompile crashes, openssl 4 pin
development
Use when stuck after multiple debug attempts and want to escalate to a stronger one-shot model (GPT-5 Pro, Opus, Gemini Pro) — packages a self-contained "oracle prompt" with Ruby/Rails project briefing, verbatim error, what-was-tried, constraints, and just-enough attached files. Triggers include "ask the oracle", "write a letter to GPT-5", "I'm stuck, draft a prompt for another model", "/tmp/letter.md".