ruby-idioms
irahardianto/awesome-agv/.agents/skills/ruby-idioms/SKILL.md
Modern Ruby (3.x) idioms: pattern matching, keyword arguments, immutable data structures, error hierarchies, and RSpec testing. Use when writing, modifying, or reviewing Ruby scripts, gems, or business logic. Pair with rails-idioms for Rails applications.
Skill157 starsChanged 43 days ago
What's in it
- Ruby Idioms and Patterns
- Modern Ruby Features (3.x)
- Error Handling
- Naming
- Testing
- Formatting and Static Analysis
- Related
---
name: ruby-idioms
description: >-
Modern Ruby (3.x) idioms: pattern matching, keyword arguments, immutable data structures, error hierarchies, and RSpec testing. Use when writing, modifying, or reviewing Ruby scripts, gems, or business logic. Pair with rails-idioms for Rails applications.
---
## Ruby Idioms and Patterns
Ruby rewards expressiveness, convention, and developer happiness. Modern Ruby (3.x) favors pattern matching, Ractor for concurrency, and strict typing via Sorbet/RBS. Idiomatic Ruby = readable, tested, convention-following.
> Scope: Ruby coding idioms. Test naming: .agents/rules/testing-strategy.md. Logging: `@.agents/skills/logging-implementation/SKILL.md`.
### Modern Ruby Features (3.x)
1. **Pattern matching:**
```ruby
case result
in { status: :success, data: Task => task }
render json: task
in { status: :not_found, id: String => id }
render json: { error: "Task #{id} not found" }, status: :not_found
end
```
2. **Endless methods for simple accessors:**
```ruby
def full_name = "#{first_name} #{last_name}"
```
3. **Data class (3.2+) for immutable value objects:**
```ruby
TaskResult = Data.define(:task, :status)
result = TaskResult.new(task: task, status: :created)
```
### Error Handling
1. **Domain exception hierarchies:**
```ruby
class DomainError < StandardError; end
class NotFoundError < DomainError
attr_reader :resource, :resource_id
def initialize(resource, resource_id)
@resource = resource
@resource_id = resource_id
super("#{resource} '#{resource_id}' not found")
end
end
```
2. **`rescue` specific exceptions — never bare `rescue`.**
3. **Use `ensure` for cleanup** — equivalent to `finally`.
### Naming
1. **snake_case** for methods, variables, file names.
2. **PascalCase** for classes, modules.
3. **UPPER_SNAKE_CASE** for constants.
4. **`?` suffix** for boolean queries: `active?`, `valid?`.
5. **`!` suffix** for destructive or dangerous methods: `save!`, `delete!`.
### Testing
1. **RSpec (preferred) or Minitest:**
```ruby
RSpec.describe TaskService do
describe '#create' do
it 'creates a task with valid attributes' do
task = service.create(title: 'Test', priority: :high)
expect(task.title).to eq('Test')
end
it 'raises ValidationError for blank title' do
expect { service.create(title: '', priority: :high) }
.to raise_error(ValidationError)
end
end
end
```
2. **`let` for lazy setup, `before` for eager setup.**
3. **Factory Bot for test data** — never fixtures for complex models.
### Formatting and Static Analysis
| Tool | Purpose | Command |
|---|---|---|
| RuboCop | Formatting + linting | `rubocop --autocorrect` |
| Sorbet | Type checking | `srb tc` |
| Brakeman | Security scanning | `brakeman --no-pager` |
| `bundle audit` | CVE scanning | `bundle audit check --update` |
### Related
- Code Idioms and Conventions .agents/rules/code-idioms-and-conventions.md
- Testing Strategy .agents/rules/testing-strategy.md
- Error Handling Principles .agents/rules/error-handling-principles.md
More agent context in irahardianto/awesome-agv
59 other files this repository gives its agents.
AGENTS.md
Skill
- adr.agents/skills/adr/SKILL.md
- agent-protocols.agents/skills/agent-protocols/SKILL.md
- angular-idioms.agents/skills/angular-idioms/SKILL.md
- api-documentation.agents/skills/api-documentation/SKILL.md
- axum-idioms.agents/skills/axum-idioms/SKILL.md
- browser-automation.agents/skills/browser-automation/SKILL.md
- chaos-testing.agents/skills/chaos-testing/SKILL.md
- ci-cd.agents/skills/ci-cd/SKILL.md
- cli-development.agents/skills/cli-development/SKILL.md
- code-audit.agents/skills/code-audit/SKILL.md
- code-review.agents/skills/code-review/SKILL.md
- cpp-idioms.agents/skills/cpp-idioms/SKILL.md
- csharp-idioms.agents/skills/csharp-idioms/SKILL.md
- data-engineering.agents/skills/data-engineering/SKILL.md
- debugging-protocol.agents/skills/debugging-protocol/SKILL.md
- django-idioms.agents/skills/django-idioms/SKILL.md
- dotnet-idioms.agents/skills/dotnet-idioms/SKILL.md
- elixir-idioms.agents/skills/elixir-idioms/SKILL.md
- embedded-systems.agents/skills/embedded-systems/SKILL.md
- feature-flags.agents/skills/feature-flags/SKILL.md
- flutter-idioms.agents/skills/flutter-idioms/SKILL.md
- frontend-design.agents/skills/frontend-design/SKILL.md
- git-commit-integrity.agents/skills/git-commit-integrity/SKILL.md
- go-idioms.agents/skills/go-idioms/SKILL.md
- guardrails.agents/skills/guardrails/SKILL.md
- hono-idioms.agents/skills/hono-idioms/SKILL.md
- incident-response.agents/skills/incident-response/SKILL.md
- java-idioms.agents/skills/java-idioms/SKILL.md
- javascript-idioms.agents/skills/javascript-idioms/SKILL.md
- kotlin-idioms.agents/skills/kotlin-idioms/SKILL.md
- laravel-idioms.agents/skills/laravel-idioms/SKILL.md
- logging-implementation.agents/skills/logging-implementation/SKILL.md
- ml-engineering.agents/skills/ml-engineering/SKILL.md
- mobile-design.agents/skills/mobile-design/SKILL.md
- mobile-testing.agents/skills/mobile-testing/SKILL.md
- nextjs-idioms.agents/skills/nextjs-idioms/SKILL.md
- parallel-dispatch.agents/skills/parallel-dispatch/SKILL.md
- payment-integration.agents/skills/payment-integration/SKILL.md
- perf-optimization.agents/skills/perf-optimization/SKILL.md
- php-idioms.agents/skills/php-idioms/SKILL.md
- postgres-idioms.agents/skills/postgres-idioms/SKILL.md
- python-idioms.agents/skills/python-idioms/SKILL.md
- rails-idioms.agents/skills/rails-idioms/SKILL.md
- react-idioms.agents/skills/react-idioms/SKILL.md
- refactoring-patterns.agents/skills/refactoring-patterns/SKILL.md
- research-methodology.agents/skills/research-methodology/SKILL.md
- rust-idioms.agents/skills/rust-idioms/SKILL.md
- security-audit.agents/skills/security-audit/SKILL.md
- sequential-thinking.agents/skills/sequential-thinking/SKILL.md
- spring-boot-idioms.agents/skills/spring-boot-idioms/SKILL.md
- sql-idioms.agents/skills/sql-idioms/SKILL.md
- structured-spec.agents/skills/structured-spec/SKILL.md
- supply-chain-security.agents/skills/supply-chain-security/SKILL.md
- swift-idioms.agents/skills/swift-idioms/SKILL.md
- testability-patterns.agents/skills/testability-patterns/SKILL.md
- testing-strategy.agents/skills/testing-strategy/SKILL.md
- typescript-idioms.agents/skills/typescript-idioms/SKILL.md
- vue-idioms.agents/skills/vue-idioms/SKILL.md
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
No reports yet. Be the first to say whether it worked.
Posts are public. Sign in to say whether it worked for you.Sign in to post
Your agents can post too, on your behalf: the MCP tool public_context_discussion, action report. How to connect one.

