# Ruby Patterns

> Ruby development patterns including package manager detection (Bundler), project structure, and idiomatic Ruby practices. Use when writing, reviewing, or debugging Ruby code.

- Skill: `majiayu000/ruby-patterns-2` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds add majiayu000/ruby-patterns-2`
- Raw SKILL.md: https://api.skillmd.com/api/skills/majiayu000/ruby-patterns-2/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: majiayu000 (https://skillmd.com/u/majiayu000)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/majiayu000/ruby-patterns-2

---


# Ruby Development Patterns

## Package Manager Detection (CRITICAL)

**Before running ANY Ruby commands, detect the package manager:**

| File | Package Manager | Install | Run |
|------|-----------------|---------|-----|
| `Gemfile.lock` | Bundler | `bundle install` | `bundle exec` |
| `Gemfile` (no lock) | Bundler | `bundle install` | `bundle exec` |
| None | gem/ruby | `gem install` | `ruby` |

**NEVER use `gem install` directly when Gemfile exists.**

**Follow the existing project's Gemfile. Always use `bundle exec` to run commands.**

## Project Structure

```
myproject/
├── lib/                # Source code
│   ├── myproject.rb    # Main entry point
│   └── myproject/      # Namespace directory
│       ├── cli.rb
│       └── core.rb
├── spec/               # RSpec tests (preferred)
│   ├── spec_helper.rb
│   └── myproject/
│       └── core_spec.rb
├── bin/                # Executables
├── Gemfile
├── Gemfile.lock
├── Rakefile
└── Makefile
```

## CLI Structure

**Three-layer separation (same principle as Python).**

