- Home
- Skills
- Kaakati
- Rails Enterprise Dev
- Ruby Oop Patterns
ruby-oop-patterns_skill
- Shell
6
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill kaakati/rails-enterprise-dev --skill ruby-oop-patterns- SKILL.md28.5 KB
Overview
This skill is a comprehensive guide to Object-Oriented Programming in Ruby and Rails, covering classes, modules, design patterns, SOLID principles, and modern Ruby 3.x features. It distills practical examples, idiomatic patterns, and Rails-specific best practices for building maintainable enterprise applications. Use it to learn, audit, or refactor Ruby code with clear, production-ready patterns.
How this skill works
The skill inspects OOP constructs and patterns: class definitions, attribute accessors, visibility rules, modules (include/prepend/extend), lookup chains, and metaprogramming techniques like define_method, method_missing, class_eval, and eigenclasses. It also explains Rails-specific structures: concerns (ActiveSupport::Concern), service objects, form and query objects, policy classes, presenters/decorators, and value objects with examples and recommended practices.
When to use it
- When designing or reviewing class and module structure for clarity and testability
- When extracting business logic into service, form, query, or policy objects
- When introducing or reducing metaprogramming to improve maintainability
- When applying SOLID principles to Rails models and controllers
- When implementing decorators, presenters, or value objects to separate concerns
Best practices
- Favor composition and small single-responsibility classes over large models
- Use ActiveSupport::Concern for shared behavior with clear class_methods and included blocks
- Limit method_missing and heavy metaprogramming; provide respond_to_missing? implementations
- Use service and form objects to keep controllers and models thin and testable
- Prefer prepend for behavior overrides and extend for class-level mixins when intent matters
Example use cases
- Refactor a fat User model into readable service objects and query objects
- Implement feature flags or behavior swaps using prepend and modular mixins
- Create form objects for complex multi-model user registration flows
- Build secure, testable authorization using Pundit policy objects and scopes
- Define dynamic attribute accessors or DSLs with define_method while preserving respond_to?
FAQ
Use modules to share orthogonal behavior across unrelated classes (mixins) and namespaces for grouping. Use inheritance when there is a true is-a relationship and shared implementation that subclasses extend.
Is metaprogramming safe in production code?
Metaprogramming is powerful but should be used sparingly. Prefer explicit code for readability; when used, add tests, clear respond_to_missing?, and document runtime behavior to avoid surprises.