skills/ruby-refactoring/SKILL.md
Automatically invoked when analyzing code quality, refactoring, or maintainability. Triggers on "code smell", "refactor", "code quality", "technical debt", "complexity", "maintainability", "clean code", "SOLID", "DRY", "improve code", "simplify", "extract method", "extract class", "long method", "large class", "duplication". Provides Ruby refactoring patterns and code smell identification based on Ruby Science methodology. NOT for object design decisions (use ruby-object-design) or Rails-specific framework patterns.
npx skillsauth add ag0os/rails-dev-plugin ruby-refactoringInstall 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.
Systematic code improvement using the Ruby Science methodology and Fowler's established refactoring catalog.
Follow this 5-step process strictly. Do not skip steps.
Systematically scan using the smell-to-pattern matrix below. See code-smells.md for Rails-specific detection heuristics.
Rank every finding into one of three tiers:
| Priority | Criteria | Examples | |----------|----------|---------| | High | Security risk, causes bugs across team, blocks feature work | N+1 in hot path, god class everyone edits, no test coverage on payment flow | | Medium | Slows development, increases onboarding time, causes merge conflicts | Duplicated logic across 3+ files, 200-line method, shotgun surgery across layers | | Low | Style inconsistency, minor readability, single-occurrence smell | One long parameter list, naming nitpick, unused private method |
Always attack high-impact, low-risk refactorings first. A refactoring is low-risk when existing tests cover the code path.
Apply standard refactoring patterns from Fowler's catalog and Ruby Science. Use the decision matrix below to map smells to patterns. Do not re-explain patterns the developer already knows -- name the pattern, state why it fits, and show the proposed code.
For every proposed refactoring, explicitly state:
Pragmatism rule: Working, maintainable code the team understands beats theoretically perfect code.
Before and after every refactoring:
| Smell | Primary Pattern | Secondary Pattern | |-------|----------------|-------------------| | Long Method (>10-15 lines) | Extract Method | Replace Method with Method Object (when many locals) | | Large Class (>100 lines) | Extract Class | Extract Module/Concern (for shared behavior) | | Long Parameter List (>3 params) | Introduce Parameter Object | Use keyword arguments | | Feature Envy | Move Method | Extract + delegate | | Primitive Obsession | Extract Value Object | Use Rails enum for states | | Complex Conditional on type | Replace Conditional with Polymorphism | Strategy pattern (when STI is overkill) | | Duplicated Code (2+ places) | Extract Method or Module | Extract shared concern | | Data Clumps | Extract Class | Introduce Parameter Object | | Shotgun Surgery | Move Method / Inline Class | See code-smells.md for Rails multi-layer detection | | Divergent Change | Extract Class | Split by axis of change |
These smells manifest differently in Rails apps than in plain Ruby. See code-smells.md for details on:
policy.person.address.zip_code) -- push logic to the owning model or use delegateExtraction target depends on the stack axes (rails-stack-profiles):
native: extract to a concern or model methodextracted: extract to a service object or POROapi: view-layer logic extracts to a serializer or form object rather than a helper or presenterStructure every refactoring recommendation as:
List each smell with severity (High/Medium/Low), file path, and line range.
Ordered list of refactoring steps. High-priority first. Each step names the specific pattern.
Before/after code for each change. Show only the transformed code -- do not re-explain what Extract Method means.
New tests needed, existing tests that must change, and suggested test run order.
How to safely deploy: feature flags, incremental PRs, or backward-compatible steps.
Before finalizing any recommendation, verify:
development
WHAT: Language-agnostic corrective guidance for the refactoring phase. WHEN: Agent is restructuring code, fixing code smells, reducing complexity, or improving maintainability. NOT FOR: Writing new features, debugging runtime errors, performance tuning, or object design decisions.
tools
Analyzes Rails view templates, partials, layouts, helpers, and form patterns for best practices. Use when reviewing ERB templates, improving view performance with fragment caching, fixing form helpers, organizing partials, adding accessibility attributes, or evaluating collection rendering. NOT for Stimulus/Turbo logic (use hotwire-patterns), controller concerns, or API-only responses.
testing
Analyzes Rails test suites and recommends testing best practices for RSpec and Minitest. Use when writing new tests, reviewing test coverage, fixing flaky tests, improving test performance, choosing between test types (unit, integration, system, request), or setting up factories and fixtures. NOT for production monitoring, deployment verification, or load/stress testing infrastructure.
development
Detects a Rails project's architecture axes — logic placement (native vs extracted) and delivery (html vs api) — so other skills load profile-appropriate guidance without inline conditionals. Use when planning architecture or when a recommendation depends on where business logic lives or whether the app renders HTML or serves JSON. NOT for test framework, job backend, cache store, or auth library choices — those are orthogonal facts detected by project-conventions.