Ruby project workflow guidelines. Activate when working with Ruby files (.rb), Gemfile, bundler, or Ruby-specific tooling.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
| Task | Tool | Command |
|------|------|---------|
| Lint | StandardRB | bundle exec standardrb |
| Format | StandardRB | bundle exec standardrb --fix |
| Type check | Sorbet | bundle exec srb tc |
| Semantic | Reek | bundle exec reek |
| Dead code | debride | bundle exec debride . |
| Complexity | Flog | bundle exec flog lib/ |
| Test | RSpec | bundle exec rspec |
| Test | Minitest | bundle exec rake test |
.ruby-version file MUST be present in project root--yjit flag or RUBY_YJIT_ENABLE=1)Pattern matching SHOULD be used for complex conditionals:
# Preferred
case response
in { status: 200, body: }
process(body)
in { status: 404 }
handle_not_found
in { status: 500.. }
handle_server_error
end
# Also valid for single patterns
response => { data: { users: } }
Data.define SHOULD be used for immutable value objects (Ruby 3.2+):
# Preferred over Struct for immutable data
Point = Data.define(:x, :y) do
def distance_from_origin
Math.sqrt(x**2 + y**2)
end
end
point = Point.new(3, 4)
point.x = 5 # => FrozenError (immutable by default)
it KeywordThe it keyword (Ruby 3.4+) SHOULD be used for single-parameter blocks:
# Preferred (Ruby 3.4+)
users.map { it.name.upcase }
# Also acceptable
users.map { _1.name.upcase }
# Legacy (still valid)
users.map { |user| user.name.upcase }
Gemfile MUST be present for all projectsGemfile.lock MUST be committed to version control# Preferred - pessimistic version constraint
gem "rails", "~> 7.1"
# Acceptable - exact version for critical deps
gem "pg", "1.5.4"
# Avoid - no version constraint
gem "nokogiri" # May break unexpectedly
| Command | Use Case |
|---------|----------|
| bundle install | Install dependencies |
| bundle update GEM | Update specific gem |
| bundle exec CMD | Run command with bundled gems |
| bundle outdated | Check for updates |
| bundle audit | Security vulnerability check |
All Ruby commands MUST use bundle exec prefix to ensure correct gem versions.
| Element | Convention | Example |
|---------|------------|---------|
| Files | snake_case | user_service.rb |
| Classes/Modules | PascalCase | UserService |
| Methods | snake_case | find_by_email |
| Variables | snake_case | current_user |
| Constants | SCREAMING_SNAKE | MAX_RETRIES |
| Predicates | trailing ? | valid?, empty? |
| Dangerous | trailing ! | save!, destroy! |
| Setters | trailing = | name= |
?!private keyword)StandardRB SHOULD be used over RuboCop for simplicity:
# .standard.yml (optional overrides)
ruby_version: 3.3
ignore:
- "db/schema.rb"
- "vendor/**/*"
# String literals - prefer double quotes
name = "Ruby"
# Symbol arrays
%i[foo bar baz]
# String arrays
%w[apple banana cherry]
# Heredocs for multiline strings
query = <<~SQL
SELECT * FROM users
WHERE active = true
SQL
# Safe navigation operator
user&.profile&.avatar_url
# Endless methods (Ruby 3.0+) for simple one-liners
def full_name = "#{first_name} #{last_name}"
# Keyword arguments SHOULD be preferred for optional params
def create_user(name:, email:, role: :member)
# ...
end
# Avoid positional arguments beyond 2-3 parameters
# Bad
def create_user(name, email, role, active, verified)
# Good
def create_user(name:, email:, role:, active:, verified:)
RSpec SHOULD be the default testing framework:
# spec/services/user_service_spec.rb
RSpec.describe UserService do
describe "#create" do
context "with valid attributes" do
it "creates a new user" do
result = described_class.new.create(name: "Test")
expect(result).to be_success
end
end
context "with invalid attributes" do
it "returns failure" do
result = described_class.new.create(name: "")
expect(result).to be_failure
end
end
end
end
describe for classes/methodscontext for conditions/scenariosit for specific behaviorslet for lazy-loaded test datalet! for eager-loaded test databefore for setup (use sparingly)# test/services/user_service_test.rb
class UserServiceTest < Minitest::Test
def test_create_with_valid_attributes
result = UserService.new.create(name: "Test")
assert result.success?
end
end
# Preferred: blocks
users.each { |user| notify(user) }
# Acceptable: lambda for callbacks
validator = ->(value) { value.present? }
# Lambda with arguments
process = ->(x, y) { x + y }
# Avoid: Proc.new unless needed
callback = Proc.new { |x| x * 2 } # Different arity handling
# Symbol to proc (preferred for simple cases)
names = users.map(&:name)
# Method reference
def process(item)
item.upcase
end
items.map(&method(:process))
define_method over method_missing when possible# Acceptable: documented DSL
class Validator
# Defines validation methods for each attribute
# @param attrs [Array<Symbol>] attribute names to validate
def self.validates(*attrs)
attrs.each do |attr|
define_method("validate_#{attr}") do
# validation logic
end
end
end
end
# Document what methods are generated
# Generated methods: validate_name, validate_email
validates :name, :email
# Avoid: unbounded method_missing
def method_missing(name, *args)
# Hard to debug, no autocomplete
end
# Prefer: explicit delegation or define_method
# Custom errors SHOULD inherit from StandardError
class ServiceError < StandardError; end
class ValidationError < ServiceError; end
# Rescue specific exceptions
begin
risky_operation
rescue ValidationError => e
handle_validation(e)
rescue ServiceError => e
handle_service_error(e)
rescue StandardError => e
handle_unexpected(e)
end
# Result objects SHOULD be used for expected failures
Result = Data.define(:success, :value, :error) do
def success? = success
def failure? = !success
def self.success(value) = new(true, value, nil)
def self.failure(error) = new(false, nil, error)
end
project/
lib/ # Application code
spec/ # RSpec tests
test/ # Minitest tests
bin/ # Executables
Gemfile # Dependencies
Gemfile.lock # Locked versions
.ruby-version # Ruby version
.standard.yml # StandardRB config (optional)
rails-workflowhanami-workflowgem-publishingSearch for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer