Ruby best practices, patterns, and idioms for building elegant, maintainable applications. Use when the task involves `Ruby project`, `Gemfile`, `Ruby on Rails`, `RSpec`, or `Ruby gems`.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Instruções da origem · Visualização somente leitura
name
ruby-development
description
Ruby best practices, patterns, and idioms for building elegant, maintainable applications. Use when the task involves `Ruby project`, `Gemfile`, `Ruby on Rails`, `RSpec`, or `Ruby gems`.
license
MIT
metadata
{"version":"1.0.0"}
Ruby Development
Production patterns and idioms for Ruby programming, covering project structure, gems, blocks,
testing, metaprogramming, and error handling.
When to Use This Skill
Starting or structuring a Ruby project
Working with Bundler and gem dependencies
Writing idiomatic Ruby with blocks, procs, and lambdas
# Guard clauses over nested conditionalsdefprocess(order)
returnunless order.valid?
returnif order.cancelled?
order.fulfill
end# Enumerable methods over manual loops
active_users = users.select(&:active?)
emails = active_users.map(&:email)
total = orders.sum(&:total)
grouped = items.group_by(&:category)
# Struct for simple value objectsCoordinate = Struct.new(:lat, :lng, keyword_init:true) dodefto_s"#{lat}, #{lng}"endend
point = Coordinate.new(lat:40.7, lng: -74.0)
# Frozen string literals (add to top of files)# frozen_string_literal: true# Hash and keyword argumentsdefcreate_user(name:, email:, role::member)
User.new(name: name, email: email, role: role)
end# Pattern matching (Ruby 3+)case response
in { status:200, body: { data:Array => items } }
process_items(items)
in { status:404 }
handle_not_found
in { status: (500..) }
handle_server_error
end
Pattern 4: Testing with RSpec
# spec/myapp/user_service_spec.rbrequire"spec_helper"RSpec.describe MyApp::UserServicedo
subject(:service) { described_class.new(repository: repository) }
let(:repository) { instance_double(MyApp::UserRepository) }
describe "#find!"do
context "when user exists"do
let(:user) { MyApp::User.new(id:"123", name:"Alice") }
before do
allow(repository).to receive(:find).with("123").and_return(user)
end
it "returns the user"do
expect(service.find!("123")).to eq(user)
endend
context "when user does not exist"do
before do
allow(repository).to receive(:find).with("999").and_return(nil)
end
it "raises NotFoundError"do
expect { service.find!("999") }
.to raise_error(MyApp::NotFoundError, /User 999 not found/)
endendend
describe "#create"do
let(:valid_params) { { email:"alice@example.com", name:"Alice" } }
it "saves the user"do
allow(repository).to receive(:save).and_return(true)
service.create(valid_params)
expect(repository).to have_received(:save).with(
an_instance_of(MyApp::User)
)
end
it "raises on invalid email"do
expect { service.create(email:nil, name:"Alice") }
.to raise_error(MyApp::ValidationError)
endendend