ruby-idioms

Provide Ruby idioms and patterns for code authoring, reviews, and refactoring.

2|Updated May 15, 2015
One-click install
npx skills add https://github.com/stephendolan/dotfiles --skill ruby-idioms
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ruby-idioms
Source: https://github.com/stephendolan/dotfiles/tree/main/claude/skills/ruby-idioms
Command: npx skills add https://github.com/stephendolan/dotfiles --skill ruby-idioms

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill promotes idiomatic Ruby that improves readability, reduces defensive coding, and aligns with community conventions.

Core Features & Use Cases

  • Expressive Style: Prefer explicit, readable constructs over clever tricks.
  • Guard Clauses: Use guard clauses at entry points for clarity.
  • Naming & Delegation: Clear method names and effective use of built-ins.

Quick Start

Refactor a method to remove an unnecessary guard and rely on a guard at entry.

Frequently Asked Questions about ruby-idioms

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write more idiomatic Ruby code?

Idiomatic Ruby prioritizes explicit, readable constructs over clever tricks. Use guard clauses at method entry points to handle edge cases early, adopt clear naming conventions, and rely on Ruby built-ins and Rails helpers. This improves maintainability and aligns with community standards.

When should I use guard clauses in Ruby?

Guard clauses belong at method entry points to exit early when preconditions fail. They eliminate unnecessary nesting, reduce defensive coding, and make intent explicit. Place them before your main logic to enforce the 'fail loud' philosophy.

What's the difference between bang and non-bang methods in Ruby?

Bang methods (with !) modify objects in-place and typically signal destructive action, while non-bang counterparts return new objects. Use bang methods intentionally and pair them with their non-bang equivalents to give users safe alternatives.

How do I organize methods by visibility in Ruby?

Organize Ruby methods by visibility: public methods first, then protected, then private. This structure clarifies the class interface and makes code easier to navigate. Follow this convention consistently across your codebase.

Should I remove guards if I have guard clauses at entry?

Yes. Guard clauses at method entry points handle preconditions, eliminating the need for defensive guards later in the method body. Removing redundant guards simplifies logic flow and makes the code more readable.