install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/pproenca/dot-skills/ruby-refactor" ~/.claude/skills/comeonoliver-skillshub-ruby-refactor && rm -rf "$T"
manifest:
skills/pproenca/dot-skills/ruby-refactor/SKILL.mdsource content
Community Ruby Refactoring Best Practices
Comprehensive refactoring guide for Ruby applications, maintained by the community. Contains 45 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Refactoring Ruby code to reduce complexity and improve design
- Extracting methods, classes, or value objects from large units
- Simplifying complex conditionals and deep nesting
- Reducing coupling between classes and modules
- Adopting idiomatic Ruby patterns and modern Ruby 3.x features
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Structure & Decomposition | CRITICAL | |
| 2 | Conditional Simplification | CRITICAL | |
| 3 | Coupling & Dependencies | HIGH | |
| 4 | Ruby Idioms | HIGH | |
| 5 | Data & Value Objects | MEDIUM-HIGH | |
| 6 | Design Patterns | MEDIUM | |
| 7 | Modern Ruby 3.x | MEDIUM | |
| 8 | Naming & Readability | LOW-MEDIUM | |
Quick Reference
1. Structure & Decomposition (CRITICAL)
- Extract Long Methods into Focused Unitsstruct-extract-method
- Extract Class for Single Responsibilitystruct-extract-class
- Introduce Parameter Object for Long Signaturesstruct-parameter-object
- Compose Methods at Single Abstraction Levelstruct-compose-method
- Replace Complex Method with Method Objectstruct-replace-method-with-object
- One Reason to Change per Classstruct-single-responsibility
- Flatten Deep Nesting with Early Extractionstruct-flatten-deep-nesting
2. Conditional Simplification (CRITICAL)
- Replace Nested Conditionals with Guard Clausescond-guard-clauses
- Extract Complex Booleans into Named Predicatescond-decompose-conditional
- Replace case/when with Polymorphismcond-replace-with-polymorphism
- Replace nil Checks with Null Objectcond-null-object
- Use Pattern Matching for Structural Conditionscond-pattern-matching
- Consolidate Duplicate Conditional Fragmentscond-consolidate-duplicates
3. Coupling & Dependencies (HIGH)
- Enforce Law of Demeter with Delegationcouple-law-of-demeter
- Move Method to Resolve Feature Envycouple-feature-envy
- Inject Dependencies via Constructor Defaultscouple-dependency-injection
- Replace Mixin with Composed Objectcouple-composition-over-inheritance
- Tell Objects What to Do, Don't Query Their Statecouple-tell-dont-ask
- Avoid Class Methods in Domain Logiccouple-avoid-class-methods-domain
4. Ruby Idioms (HIGH)
- Use map/select/reject Over each with Accumulatoridiom-prefer-enumerable
- Use Keyword Arguments for Clarityidiom-keyword-arguments
- Use respond_to? Over is_a? for Type Checkingidiom-duck-typing
- Name Boolean Methods with ? Suffixidiom-predicate-methods
- Always Pair method_missing with respond_to_missing?idiom-respond-to-missing
- Use yield Over block.call for Simple Blocksidiom-block-yield
- Omit Explicit return for Last Expressionidiom-implicit-return
5. Data & Value Objects (MEDIUM-HIGH)
- Replace Primitive Obsession with Value Objectsdata-value-object
- Use Data.define for Immutable Value Objectsdata-define-immutable
- Encapsulate Collections Behind Domain Methodsdata-encapsulate-collection
- Replace Data Clumps with Grouped Objectsdata-replace-data-clump
- Separate Query Methods from Command Methodsdata-separate-query-command
6. Design Patterns (MEDIUM)
- Extract Algorithm Variations into Strategy Objectspattern-strategy
- Use Factory Method to Abstract Object Creationpattern-factory
- Define Algorithm Skeleton with Template Methodpattern-template-method
- Wrap Objects with Decorator for Added Behaviorpattern-decorator
- Implement Null Object with Full Protocolpattern-null-object-protocol
7. Modern Ruby 3.x (MEDIUM)
- Use case/in for Structural Pattern Matchingmodern-pattern-matching
- Implement deconstruct_keys for Custom Pattern Matchingmodern-deconstruct-keys
- Use Endless Method Definition for Simple Methodsmodern-endless-methods
- Use Pattern Matching with Guard Clausesmodern-hash-pattern-guard
- Use Rightward Assignment for Pipeline Expressionsmodern-rightward-assignment
8. Naming & Readability (LOW-MEDIUM)
- Use Intention-Revealing Namesname-intention-revealing
- Use One Word per Concept Across Codebasename-consistent-vocabulary
- Spell Out Names Except Universal Abbreviationsname-avoid-abbreviations
- Rename to Eliminate Need for Commentsname-rename-to-remove-comments
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Reference Files
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |