Help us improve
Share bugs, ideas, or general feedback.
From majestic-rails
Guides writing new Ruby code with modern 3.x syntax, Sandi Metz's 4 rules for developers, and idiomatic best practices. Use for creating files, methods, or refactoring to ensure clarity, simplicity, and maintainability.
npx claudepluginhub majesticlabs-dev/majestic-marketplace --plugin majestic-railsHow this skill is triggered — by the user, by Claude, or both
Slash command
/majestic-rails:ruby-coderThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Use hash shorthand when keys match variable names:
Writes idiomatic Ruby code using metaprogramming, Rails patterns, and performance optimization. Covers Rails apps, gem development, RSpec/Minitest testing, RuboCop.
Generates Ruby on Rails code in DHH's 37signals style: short REST-only controllers, fat models with scopes and broadcasting, Current attributes, indented private methods, and Ruby syntax like %i[] arrays and expression-less cases.
Applies DHH/37signals Rails conventions to Ruby code: fat models, thin controllers, REST purity, Hotwire patterns, database-first approach, avoiding Redis/service objects.
Share bugs, ideas, or general feedback.
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.
These rules enforce strict limits to maintain code quality. Breaking them requires explicit justification.
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
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)
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
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
@_calculation@user.profile.avatar -> use facade methodUse 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
Design operations to be safely repeatable:
def activate_user
return if user.active?
user.update(active: true)
send_activation_email unless email_sent?
end
Extract classes when:
Extract methods when:
Use parameter objects when:
Create facades when:
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/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