{"slug":"ruby","title":"ruby","summary":"Use when writing Ruby or working in Rails codebases. Covers idiomatic object design, service objects, ActiveRecord query performance, RSpec structure, and RuboCop-clean style. Trigger on \"this rails controller is too fat\", \"activerecord is doing n+1 queries\", \"clean up this rspec","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-11-09T16:52:46.447901Z","repo":{"url":"https://github.com/nimadorostkar/Claude-Skills-collection","stars":34,"forks":4,"license":"MIT","updatedAt":"2026-11-08T15:41:45Z"},"bodyHtml":"<hr>\n<h2>name: ruby\ndescription: Use when writing Ruby or working in Rails codebases. Covers idiomatic object design, service objects, ActiveRecord query performance, RSpec structure, and RuboCop-clean style. Trigger on \"this rails controller is too fat\", \"activerecord is doing n+1 queries\", \"clean up this rspec suite\", \"rubocop keeps complaining\". Do not use for language-agnostic job queue design — see the background-jobs skill.\nmetadata:\ncategory: languages\nversion: 1.0.0\ntags: [ruby, rails, activerecord, rspec, rubocop]</h2>\n<h1>Ruby</h1>\n<h2>Purpose</h2>\n<p>Write Ruby that stays readable as it grows: small objects with clear responsibilities, controllers that stay thin, and ActiveRecord queries that do not quietly issue a query per row.</p>\n<h2>When to Use</h2>\n<ul>\n<li>Writing or reviewing Ruby and Rails code.</li>\n<li>Refactoring fat models or fat controllers.</li>\n<li>Diagnosing slow endpoints caused by ActiveRecord.</li>\n<li>Structuring an RSpec suite.</li>\n<li>Designing background jobs and their retry semantics.</li>\n</ul>\n<h2>Capabilities</h2>\n<ul>\n<li>Object design: service objects, form objects, query objects, value objects.</li>\n<li>ActiveRecord: eager loading, scopes, batching, index-aware querying.</li>\n<li>Background processing with Sidekiq or Active Job, including idempotency.</li>\n<li>RSpec structure: request specs, model specs, factories, shared examples.</li>\n<li>RuboCop and Sorbet/RBS typing where valuable.</li>\n</ul>\n<h2>Inputs</h2>\n<ul>\n<li>Application source, Gemfile, Rails version.</li>\n<li>Slow-query or profiling data when performance is the concern.</li>\n</ul>\n<h2>Outputs</h2>\n<ul>\n<li>Controllers that authenticate, authorize, delegate, and render — nothing else.</li>\n<li>Named scopes and eager-loaded queries with no N+1.</li>\n<li>Specs that describe behavior rather than restate implementation.</li>\n</ul>\n<h2>Workflow</h2>\n<ol>\n<li><strong>Locate the responsibility</strong> — If a method touches HTTP, business rules, and persistence, split it before changing it.</li>\n<li><strong>Extract a service object</strong> — One public <code>call</code>, explicit dependencies, no global state.</li>\n<li><strong>Fix the queries</strong> — Add <code>includes</code>, convert loops into set operations, batch with <code>find_each</code>.</li>\n<li><strong>Make jobs idempotent</strong> — Retries are guaranteed; double-execution must be harmless.</li>\n<li><strong>Gate</strong> — RSpec, RuboCop, and Bullet (or equivalent) to fail the build on N+1.</li>\n</ol>\n<h2>Best Practices</h2>\n<ul>\n<li>Controllers do not contain business logic. If a controller action exceeds ten lines, extract.</li>\n<li>Callbacks (<code>after_save</code>, <code>before_create</code>) create action at a distance. Prefer explicit service calls.</li>\n<li>Use <code>find_each</code> for anything that could exceed a few thousand rows; <code>all.each</code> loads the table into memory.</li>\n<li>Every background job should be safe to run twice. Key the side effect, not the invocation.</li>\n<li><code>rescue =&gt; e</code> without re-raising swallows bugs. Rescue the specific class.</li>\n<li>Freeze constants and prefer immutable value objects for domain concepts.</li>\n</ul>\n<h2>Examples</h2>\n<p><strong>Service object with explicit failure:</strong></p>\n<pre><code># frozen_string_literal: true\n\nclass RefundOrder\n  Result = Struct.new(:success?, :refund, :error, keyword_init: true)\n\n  def initialize(gateway: PaymentGateway.new)\n    @gateway = gateway\n  end\n\n  def call(order:, amount_cents:)\n    return failure(\"order not refundable\") unless order.refundable?\n    return failure(\"amount exceeds order total\") if amount_cents &gt; order.total_cents\n\n    refund = @gateway.refund(order.charge_id, amount_cents)\n    order.update!(refunded_cents: order.refunded_cents + amount_cents)\n    Result.new(success?: true, refund: refund)\n  rescue PaymentGateway::Error =&gt; e\n    failure(e.message)\n  end\n\n  private\n\n  def failure(message) = Result.new(success?: false, error: message)\nend\n</code></pre>\n<h2>Notes</h2>\n<ul>\n<li>Bullet in the test environment, configured to raise, turns N+1 queries into failing tests.</li>\n<li><code>frozen_string_literal: true</code> is worth adding to every file; string allocation is a real cost in hot paths.</li>\n<li>Sidekiq retries with exponential backoff by default. Set <code>sidekiq_options retry:</code> explicitly rather than relying on the default for anything that touches money.</li>\n</ul>\n","files":[{"path":"SKILL.md","sizeBytes":3931,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-11-09T16:52:59.274846Z","sha256":"CDF561B9C3CCB3DB25BFDD240A3EB2493A617192FA136B3E66D8A5E2F363F6C2","sizeBytes":2026},"review":null,"source":{"repositoryUrl":"https://github.com/nimadorostkar/Claude-Skills-collection","path":"skills/languages/ruby","license":"MIT","commit":"1691932edc17063d712a85d02bcc7a1cd3791057","subtreeSha":"8CDDE338BE56493AF62DA6DE2F8AB4DF803914ED1FE4A2888CA1D32C4D0F4E57","lastSyncedAt":"2026-11-09T16:52:45.174974Z"},"reviewedAt":"2026-11-09T16:53:34.441736Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/nimadorostkar/Claude-Skills-collection/tree/main/skills/languages/ruby"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install nimadorostkar-claude-skills-collection@llmmart"},{"target":"git","command":"git clone https://github.com/nimadorostkar/Claude-Skills-collection.git"}]}