ruby
Master Ruby language conventions and modern features (3.x+) for writing clean, performant code. This skill covers error handling strategies, pattern matching, and Ruby idioms like guard clauses and safe navigation. Use it when writing pure Ruby, optimizing performance, or establishing team conventions—separate skills handle Rails, design patterns, testing, and style.
Ruby helps you write idiomatic code using modern 3.x+ conventions, error handling patterns, and performance techniques.
AI-generated summary based on this skill's SKILL.md
Decision gist · record as of 2026-07-22
Ruby helps you write idiomatic code using modern 3.x+ conventions, error handling patterns, and performance techniques. Master Ruby language conventions and modern features (3.x+) for writing clean, performant code. This skill covers error handling strategies, pattern matching, and Ruby idioms like guard clauses and safe navigation. Use it when writing pure Ruby, optimizing performance, or establishing team conventions—separate skills handle Rails, design patterns, testing, and style.
Use it when
- Ruby error handling patterns emphasize custom exception hierarchies and result objects.
- Ruby 3.x introduces pattern matching with `case/in` syntax for destructuring complex data structures elegantly.
Verify before relying
Read SKILL.md below before installing (4 files). Open directory: indexed for reading, not audited.
Install
el-feo/ai-context/ruby · repository language: Ruby
Open directory. Skills are indexed for reading, not audited. Review a skill's body before installing it.
Frequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
How do I write idiomatic Ruby code following modern conventions?
Ruby emphasizes readability and expressiveness. Write idiomatic Ruby by using guard clauses to exit early, leveraging the safe navigation operator (&.) to avoid nil checks, and naming predicate methods with a trailing question mark. Prefer `hash.fetch(:key)` over bracket access for safer defaults, use frozen string literals to reduce memory overhead, and embrace blocks and iterators rather than imperative loops. Ruby 3.x+ idioms also include pattern matching for elegant case statements and lazy enumerables for memory-efficient transformations on large datasets.
What are ruby error handling patterns and best practices?
Ruby error handling patterns emphasize custom exception hierarchies and result objects. Define domain-specific exceptions inheriting from StandardError to signal specific failure modes. Use `raise` (not `fail`) to throw exceptions, and rescue specific exception types rather than catching all errors. For operations that may fail without exceptional circumstances, return result objects—lightweight wrappers holding success/failure state and values. This separates error signaling (exceptions for truly exceptional cases) from expected failure handling (result objects for business logic failures), improving code clarity and testability.
What ruby 3.x idioms and conventions should I follow?
Ruby 3.x introduces pattern matching with `case/in` syntax for destructuring complex data structures elegantly. Use data classes (via Struct or Data) to define immutable value objects with minimal boilerplate. Adopt frozen string literals by default to reduce garbage collection pressure. Leverage the safe navigation operator (&.) and the endless method syntax (`def name = value`) for concise definitions. Prefer keyword arguments over positional ones for clarity, and use numbered block parameters (`_1`, `_2`) in single-line blocks. These conventions make Ruby 3.x code more expressive and performant.
How can I optimize Ruby performance with frozen strings and lazy enums?
Ruby performance optimization starts with frozen string literals—add `# frozen_string_literal: true` at file tops to prevent string duplication and reduce memory. Use lazy enumerables (`Enumerator::Lazy`) when chaining transformations on large collections; they defer computation until terminal operations, avoiding intermediate arrays. Memoize expensive calculations using instance variables or the `||=` pattern. Avoid string concatenation in loops; use `String#<<` or `Array#join` instead. Profile with `ruby-prof` to identify bottlenecks, and consider using `Fiber` or `Ractor` for concurrent workloads in Ruby 3.x+.
What are ruby data class immutable objects and pattern matching examples?
Ruby data classes create immutable value objects with minimal syntax. Use `Data.define(:field1, :field2)` (Ruby 3.2+) or `Struct.new` to define frozen records. Pattern matching with `case/in` destructures these objects elegantly: `case user; in Data(name:, age:) if age >= 18; ...; end`. This replaces verbose conditional logic with readable guards. Data classes pair naturally with pattern matching to handle complex domain models—each case branch extracts only needed fields, reducing intermediate variables and improving maintainability.
What's the difference between fail and raise in Ruby?
Ruby's `raise` and `fail` are aliases—both throw exceptions identically. Modern Ruby style prefers `raise` because it's more explicit about intent: you're raising an error condition. `fail` is a legacy convention from older Ruby versions and is rarely used in contemporary code. Always use `raise` with a specific exception class and message: `raise ArgumentError, 'invalid input'`. This clarity helps maintainers understand that an exceptional condition occurred, not a normal control flow decision.
SKILL.md
Rendered from the published skill. Quoted content, verbatim.
Ruby Language Skill
Error Handling Conventions
Weirich raise/fail Convention
Use fail for first-time exceptions, raise only for re-raising:
def process(order)
fail ArgumentError, "Order cannot be nil" if order.nil?
begin
gateway.charge(order)
rescue PaymentError => e
logger.error("Payment failed: #{e.message}")
raise # re-raise with raise
end
end
Custom Exception Hierarchies
Group domain exceptions under a base error:
```ruby module MyApp class Error < StandardError; end class PaymentError < Error; end class InsufficientFundsError < PaymentError; end end
Rescue at any
(truncated - see the full file via the links below)
File tree — 4 files
plugins/ruby-rails/skills/ruby/SKILL.md
plugins/ruby-rails/skills/ruby/references/error_handling.md
plugins/ruby-rails/skills/ruby/references/modern_ruby.md
plugins/ruby-rails/skills/ruby/references/performance.md
Let your AI agent find skills like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 56,283 agent skills by what they can do, searchable in plain language.
wish › “Write idiomatic Ruby code following modern conventions and best practices”
Give your agent the search over MCP, or paste the wish link into any chat. No install? Search from any chat →
Related skills
Ruby Patterns covers essential idioms and architectural approaches for Rails and Ruby development. Learn blocks, procs, lambdas, modules, metaprogramming techniques, pattern matching, and enumerable chains alongside testing strategies with RSpec, error handling patterns, and project structure conventions for gems and Rails apps.
This skill teaches core Ruby patterns including classes, modules, inheritance, and mixins alongside functional programming with blocks, procs, and lambdas. It covers enumerable operations, lazy evaluation, and metaprogramming techniques like method_missing and dynamic method definition, plus error handling strategies and RSpec testing.
Ruby Patterns equips you with creational, structural, and behavioral design patterns alongside modern Ruby idioms and metaprogramming techniques. Reference common shortcuts for conditionals, enumerables, and strings, then dive into factory, builder, decorator, strategy, and observer patterns with working examples. Use it to refactor for clarity and apply proven architectural approaches.
A reference for writing idiomatic Elixir code aligned with BEAM architecture and OTP patterns. Covers GenServer, Supervisor, Task, Registry, pattern matching, and the core principles that make concurrent systems reliable—including eleven iron laws never to violate and decision trees for control flow, error handling, and process design.
This skill covers idiomatic PHP 8.x development, emphasizing strict typing, immutable data structures via readonly classes and enums, and domain-driven error handling. Learn named arguments, match expressions, constructor injection, and PSR-12 naming conventions alongside static analysis tools like PHPStan and Psalm.
This skill covers the core patterns that make Elixir code functional and resilient. Learn pattern matching across function heads and case expressions, build stateful processes with GenServer, and embrace the supervision model's "let it crash" philosophy. The skill also covers pipe-friendly API design, naming conventions, and tools like Credo and Dialyzer for code quality.
More skills Java Idioms (MIT)