ruby-coder
Provides standards for Ruby 3.x development, focusing on method length limits and class responsibilities.
Install
mkdir -p .claude/skills/ruby-coder && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/478" && unzip -o skill.zip -d .claude/skills/ruby-coder && rm skill.zipInstalls to .claude/skills/ruby-coder
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
This skill guides writing of new Ruby code following modern Ruby 3.x syntax, Sandi Metz's 4 Rules for Developers, and idiomatic Ruby best practices. Use when creating new Ruby files, writing Ruby methods, or refactoring Ruby code to ensure adherence to clarity, simplicity, and maintainability standards.Key capabilities
- →Write new Ruby code following Ruby 3.x syntax
- →Refactor Ruby code to adhere to Sandi Metz's 4 Rules
- →Extract secondary concerns into new classes
- →Use parameter objects for methods with many arguments
- →Design idempotent operations for repeatability
- →Create facades for controllers needing multiple objects
How it works
The skill applies Sandi Metz's 4 Rules for Developers, which set strict limits on class length, method length, parameter count, and object instantiation in controllers. It also guides the use of modern Ruby 3.x syntax and best practices for thread safety and idempotency.
Inputs & outputs
When to use ruby-coder
- →Refactoring long methods
- →Creating new Ruby classes
- →Updating legacy Ruby code to 3.x
- →Standardizing naming conventions
About this skill
Ruby Coder
Ruby 3.x Modern Syntax
Use hash shorthand when keys match variable names:
age = 49
name = "David"
user = { name:, age: }
For general naming conventions, semantic methods, and enumerable patterns, see references/ruby-style-conventions.md.
Sandi Metz's 4 Rules for Developers
These rules enforce strict limits to maintain code quality. Breaking them requires explicit justification.
Rule 1: Classes Can Be No Longer Than 100 Lines
Limit: Maximum 100 lines of code per class
Check: When a class exceeds this limit, extract secondary concerns to new classes
# When exceeding 100 lines, extract secondary concerns:
class UserProfilePresenter # Presentation logic
class UserProfileValidator # Validation logic
class UserProfileNotifier # Notification logic
Exceptions: Valid Single Responsibility Principle (SRP) justification required
Rule 2: Methods Can Be No Longer Than 5 Lines
Limit: Maximum 5 lines per method. Each if/else branch counts as lines.
# Good - 5 lines or fewer
def process_order
validate_order
calculate_totals
apply_discounts
finalize_payment
end
# Avoid - extract when too long
def process_order
return unless items.any?
return unless valid_address?
self.subtotal = items.sum(&:price)
self.tax = subtotal * tax_rate
self.total = subtotal + tax
charge_customer
send_confirmation
end
Exceptions: Pair approval required (Rule 0: break rules with agreement)
Rule 3: Pass No More Than 4 Parameters
Limit: Maximum 4 parameters per method. Use parameter objects or hashes when more data is needed.
# Parameter object when data is related
def create_post(post_params)
Post.create(user: post_params.user, title: post_params.title, content: post_params.content)
end
Exceptions: Rails view helpers like link_to or form_for are exempt
Rule 4: Controllers May Instantiate Only One Object
Limit: Controllers should instantiate only one object; other objects come through that via facade pattern.
# Good - single object via facade
class DashboardController < ApplicationController
def show
@dashboard = DashboardFacade.new(current_user)
end
end
# Avoid - multiple instance variables
class DashboardController < ApplicationController
def show
@user = current_user
@posts = @user.posts.recent
@notifications = @user.notifications.unread
end
end
- Prefix unused instance variables with underscore:
@_calculation - Avoid direct collaborator access in views:
@user.profile.avatar-> use facade method
Code Quality Standards
Thread Safety
Use Mutex for shared mutable state:
class Configuration
@instance_mutex = Mutex.new
def self.instance
return @instance if @instance
@instance_mutex.synchronize { @instance ||= new }
end
end
Idempotent Operations
Design operations to be safely repeatable:
def activate_user
return if user.active?
user.update(active: true)
send_activation_email unless email_sent?
end
Refactoring Triggers
Extract classes when:
- Class exceeds 100 lines (Sandi Metz Rule 1)
- Class has multiple responsibilities
- Class name contains "And" or "Or"
Extract methods when:
- Method exceeds 5 lines (Sandi Metz Rule 2)
- Conditional logic is complex
- Code has nested loops or conditionals
- Comments explain what code does (code should be self-explanatory)
Use parameter objects when:
- Methods require more than 4 parameters (Sandi Metz Rule 3)
- Related parameters are always passed together
- Parameter list is growing over time
Create facades when:
- Controllers need multiple objects (Sandi Metz Rule 4)
- Views access nested collaborators
- Complex data aggregation is needed
When to Break Rules
Sandi Metz's "Rule 0": Break any of the 4 rules only with pair approval or clear justification.
| Rule | Valid Exception |
|---|---|
| 100 lines | Clear SRP justification required |
| 5 lines | Complex but irreducible algorithms |
| 4 params | Rails view helpers exempt |
| 1 object | Simple views without facades |
Document all exceptions with clear reasoning in code comments.
References
references/sandi-metz.md- Code smells, refactoring, testing principlesreferences/ruby-tips.md- Type conversion, hash patterns, proc composition, refinementsreferences/ruby-style-conventions.md- Naming, semantic methods, enumerables, composition
When not to use it
- →When a class exceeding 100 lines has a valid Single Responsibility Principle justification
- →When a method exceeding 5 lines is a complex but irreducible algorithm
- →When a method requires more than 4 parameters for Rails view helpers
Limitations
- →Class length is limited to 100 lines, with exceptions requiring SRP justification
- →Method length is limited to 5 lines, with exceptions requiring pair approval
- →Methods are limited to 4 parameters, with exceptions for Rails view helpers
How it compares
This skill provides specific, quantifiable rules for Ruby code structure and syntax, unlike generic style guides that may offer broader recommendations without strict limits.
Compared to similar skills
ruby-coder side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| ruby-coder (this skill) | 5 | 5mo | No flags | Intermediate |
| editor | 0 | 4mo | No flags | Intermediate |
| ruby-pro | 1 | 4mo | No flags | Advanced |
| skill-rails-upgrade | 1 | 3mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
editor
betagouv
when generating content for ruby or slim files, follow the style and conventions of the existing codebase. Use the existing code as a guide for formatting, naming, and structure. When asked to write new code, prefer to reuse patterns and styles already present in the codebase.
ruby-pro
sickn33
Write idiomatic Ruby code with metaprogramming, Rails patterns, and performance optimization. Specializes in Ruby on Rails, gem development, and testing frameworks. Use PROACTIVELY for Ruby refactoring, optimization, or complex Ruby features.
skill-rails-upgrade
sickn33
Analyze Rails apps and provide upgrade assessments
lint
i3ringit
Use this agent when you need to run linting and code quality checks on Ruby and ERB files. Run before pushing to origin.
rspec-unit-testing-standards
ruby-git
Defines RSpec unit testing rules for this project covering structure, naming, setup patterns, stubbing, doubles, coverage, and test reliability. Use when writing, reviewing, or auditing RSpec specs under spec/unit/.
upgrade-dependencies
codenamev
Upgrade all Ruby gem dependencies to their latest versions with release note review and codebase alignment checks. Use this skill whenever the user asks to update, upgrade, or bump dependencies, gems, or packages — even casually like 'update my gems' or 'are my deps up to date?'