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
struct-
2
Conditional Simplification
CRITICAL
cond-
3
Coupling & Dependencies
HIGH
couple-
4
Ruby Idioms
HIGH
idiom-
5
Data & Value Objects
MEDIUM-HIGH
data-
6
Design Patterns
MEDIUM
pattern-
7
Modern Ruby 3.x
MEDIUM
modern-
8
Naming & Readability
LOW-MEDIUM
name-
Quick Reference
1. Structure & Decomposition (CRITICAL)
struct-extract-method - Extract Long Methods into Focused Units
struct-extract-class - Extract Class for Single Responsibility
struct-parameter-object - Introduce Parameter Object for Long Signatures
struct-compose-method - Compose Methods at Single Abstraction Level
struct-replace-method-with-object - Replace Complex Method with Method Object
struct-single-responsibility - One Reason to Change per Class
struct-flatten-deep-nesting - Flatten Deep Nesting with Early Extraction
2. Conditional Simplification (CRITICAL)
cond-guard-clauses - Replace Nested Conditionals with Guard Clauses
cond-decompose-conditional - Extract Complex Booleans into Named Predicates
cond-replace-with-polymorphism - Replace case/when with Polymorphism
cond-null-object - Replace nil Checks with Null Object
cond-pattern-matching - Use Pattern Matching for Structural Conditions
data-replace-data-clump - Replace Data Clumps with Grouped Objects
data-separate-query-command - Separate Query Methods from Command Methods
6. Design Patterns (MEDIUM)
pattern-strategy - Extract Algorithm Variations into Strategy Objects
pattern-factory - Use Factory Method to Abstract Object Creation
pattern-template-method - Define Algorithm Skeleton with Template Method
pattern-decorator - Wrap Objects with Decorator for Added Behavior
pattern-null-object-protocol - Implement Null Object with Full Protocol
7. Modern Ruby 3.x (MEDIUM)
modern-pattern-matching - Use case/in for Structural Pattern Matching
modern-deconstruct-keys - Implement deconstruct_keys for Custom Pattern Matching
modern-endless-methods - Use Endless Method Definition for Simple Methods
modern-hash-pattern-guard - Use Pattern Matching with Guard Clauses
modern-rightward-assignment - Use Rightward Assignment for Pipeline Expressions
8. Naming & Readability (LOW-MEDIUM)
name-intention-revealing - Use Intention-Revealing Names
name-consistent-vocabulary - Use One Word per Concept Across Codebase
name-avoid-abbreviations - Spell Out Names Except Universal Abbreviations
name-rename-to-remove-comments - Rename to Eliminate Need for 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
1---2name: ruby-refactor3description: Community Ruby Refactoring Best Practices4---5# Community Ruby Refactoring Best Practices67Comprehensive 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.89## When to Apply1011Reference these guidelines when:12- Refactoring Ruby code to reduce complexity and improve design13- Extracting methods, classes, or value objects from large units14- Simplifying complex conditionals and deep nesting15- Reducing coupling between classes and modules16- Adopting idiomatic Ruby patterns and modern Ruby 3.x features1718## Rule Categories by Priority1920| Priority | Category | Impact | Prefix |21|----------|----------|--------|--------|22| 1 | Structure & Decomposition | CRITICAL | `struct-` |23| 2 | Conditional Simplification | CRITICAL | `cond-` |24| 3 | Coupling & Dependencies | HIGH | `couple-` |25| 4 | Ruby Idioms | HIGH | `idiom-` |26| 5 | Data & Value Objects | MEDIUM-HIGH | `data-` |27| 6 | Design Patterns | MEDIUM | `pattern-` |28| 7 | Modern Ruby 3.x | MEDIUM | `modern-` |29| 8 | Naming & Readability | LOW-MEDIUM | `name-` |3031## Quick Reference3233### 1. Structure & Decomposition (CRITICAL)3435- [`struct-extract-method`](references/struct-extract-method.md) - Extract Long Methods into Focused Units36- [`struct-extract-class`](references/struct-extract-class.md) - Extract Class for Single Responsibility37- [`struct-parameter-object`](references/struct-parameter-object.md) - Introduce Parameter Object for Long Signatures38- [`struct-compose-method`](references/struct-compose-method.md) - Compose Methods at Single Abstraction Level39- [`struct-replace-method-with-object`](references/struct-replace-method-with-object.md) - Replace Complex Method with Method Object40- [`struct-single-responsibility`](references/struct-single-responsibility.md) - One Reason to Change per Class41- [`struct-flatten-deep-nesting`](references/struct-flatten-deep-nesting.md) - Flatten Deep Nesting with Early Extraction4243### 2. Conditional Simplification (CRITICAL)4445- [`cond-guard-clauses`](references/cond-guard-clauses.md) - Replace Nested Conditionals with Guard Clauses46- [`cond-decompose-conditional`](references/cond-decompose-conditional.md) - Extract Complex Booleans into Named Predicates47- [`cond-replace-with-polymorphism`](references/cond-replace-with-polymorphism.md) - Replace case/when with Polymorphism48- [`cond-null-object`](references/cond-null-object.md) - Replace nil Checks with Null Object49- [`cond-pattern-matching`](references/cond-pattern-matching.md) - Use Pattern Matching for Structural Conditions50- [`cond-consolidate-duplicates`](references/cond-consolidate-duplicates.md) - Consolidate Duplicate Conditional Fragments5152### 3. Coupling & Dependencies (HIGH)5354- [`couple-law-of-demeter`](references/couple-law-of-demeter.md) - Enforce Law of Demeter with Delegation55- [`couple-feature-envy`](references/couple-feature-envy.md) - Move Method to Resolve Feature Envy56- [`couple-dependency-injection`](references/couple-dependency-injection.md) - Inject Dependencies via Constructor Defaults57- [`couple-composition-over-inheritance`](references/couple-composition-over-inheritance.md) - Replace Mixin with Composed Object58- [`couple-tell-dont-ask`](references/couple-tell-dont-ask.md) - Tell Objects What to Do, Don't Query Their State59- [`couple-avoid-class-methods-domain`](references/couple-avoid-class-methods-domain.md) - Avoid Class Methods in Domain Logic6061### 4. Ruby Idioms (HIGH)6263- [`idiom-prefer-enumerable`](references/idiom-prefer-enumerable.md) - Use map/select/reject Over each with Accumulator64- [`idiom-keyword-arguments`](references/idiom-keyword-arguments.md) - Use Keyword Arguments for Clarity65- [`idiom-duck-typing`](references/idiom-duck-typing.md) - Use respond_to? Over is_a? for Type Checking66- [`idiom-predicate-methods`](references/idiom-predicate-methods.md) - Name Boolean Methods with ? Suffix67- [`idiom-respond-to-missing`](references/idiom-respond-to-missing.md) - Always Pair method_missing with respond_to_missing?68- [`idiom-block-yield`](references/idiom-block-yield.md) - Use yield Over block.call for Simple Blocks69- [`idiom-implicit-return`](references/idiom-implicit-return.md) - Omit Explicit return for Last Expression7071### 5. Data & Value Objects (MEDIUM-HIGH)7273- [`data-value-object`](references/data-value-object.md) - Replace Primitive Obsession with Value Objects74- [`data-define-immutable`](references/data-define-immutable.md) - Use Data.define for Immutable Value Objects75- [`data-encapsulate-collection`](references/data-encapsulate-collection.md) - Encapsulate Collections Behind Domain Methods76- [`data-replace-data-clump`](references/data-replace-data-clump.md) - Replace Data Clumps with Grouped Objects77- [`data-separate-query-command`](references/data-separate-query-command.md) - Separate Query Methods from Command Methods7879### 6. Design Patterns (MEDIUM)8081- [`pattern-strategy`](references/pattern-strategy.md) - Extract Algorithm Variations into Strategy Objects82- [`pattern-factory`](references/pattern-factory.md) - Use Factory Method to Abstract Object Creation83- [`pattern-template-method`](references/pattern-template-method.md) - Define Algorithm Skeleton with Template Method84- [`pattern-decorator`](references/pattern-decorator.md) - Wrap Objects with Decorator for Added Behavior85- [`pattern-null-object-protocol`](references/pattern-null-object-protocol.md) - Implement Null Object with Full Protocol8687### 7. Modern Ruby 3.x (MEDIUM)8889- [`modern-pattern-matching`](references/modern-pattern-matching.md) - Use case/in for Structural Pattern Matching90- [`modern-deconstruct-keys`](references/modern-deconstruct-keys.md) - Implement deconstruct_keys for Custom Pattern Matching91- [`modern-endless-methods`](references/modern-endless-methods.md) - Use Endless Method Definition for Simple Methods92- [`modern-hash-pattern-guard`](references/modern-hash-pattern-guard.md) - Use Pattern Matching with Guard Clauses93- [`modern-rightward-assignment`](references/modern-rightward-assignment.md) - Use Rightward Assignment for Pipeline Expressions9495### 8. Naming & Readability (LOW-MEDIUM)9697- [`name-intention-revealing`](references/name-intention-revealing.md) - Use Intention-Revealing Names98- [`name-consistent-vocabulary`](references/name-consistent-vocabulary.md) - Use One Word per Concept Across Codebase99- [`name-avoid-abbreviations`](references/name-avoid-abbreviations.md) - Spell Out Names Except Universal Abbreviations100- [`name-rename-to-remove-comments`](references/name-rename-to-remove-comments.md) - Rename to Eliminate Need for Comments101102## How to Use103104Read individual reference files for detailed explanations and code examples:105106- [Section definitions](references/_sections.md) - Category structure and impact levels107- [Rule template](assets/templates/_template.md) - Template for adding new rules108109## Reference Files110111| File | Description |112|------|-------------|113| [references/_sections.md](references/_sections.md) | Category definitions and ordering |114| [assets/templates/_template.md](assets/templates/_template.md) | Template for new rules |115| [metadata.json](metadata.json) | Version and reference information |
Run npx skillmds@latest add comeonoliver/ruby-refactor in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Community Ruby Refactoring Best Practices It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
ComeOnOliver (@comeonoliver) published this skill. Their other Agent Skills are listed on their SkillMD profile.