Skip to content
Back to skills

Ruby Script

ASecurity

Use when writing a Ruby script. Covers the template, conventions, and required patterns.

  • 3 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 10, 2026
ai-agentsgorubytesting

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned November 21, 2026

npx -y skills add LandonSchropp/agent-toolkit --skill ruby-script --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ruby Script?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Ruby Script
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/landonschropp-ruby-script/badge)](https://www.skillsdirectory.com/skills/landonschropp-ruby-script)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: ruby-script
description: Use when writing a Ruby script. Covers the template, conventions, and required patterns.
---

Before writing the script, read [Testing](references/testing.md).

## Template

Two templates cover the two kinds of scripts. Copy the right one exactly and fill in the specific logic.

- **Simple:** Scripts intended to be run directly by a user. These typically take either no arguments or a single positional argument. Start from [`assets/template-simple.rb`](assets/template-simple.rb). It shows the one-argument form; if the script takes no arguments, delete the argument check and keep the top comment.
- **Complex:** Scripts capable of taking multiple arguments via flags. Skill scripts should _always_ be considered complex scripts. Start from [`assets/template-complex.rb`](assets/template-complex.rb). These always support `--help`.

## Conventions

- File: `<name>.rb` with kebab-case (e.g., `extract-pr-number.rb`)
- Make the file executable (`chmod +x`)
- Flag-based arguments using `--flag-name` (kebab-case). Only use positional args for very simple cases.
- Arguments are always required. Never make script arguments optional unless the user _explicitly_ asks for it.
- Full variable names (`directory`, not `dir`)
- Call other commands with their long flags (`--session=main`, not `-s main`), so the call reads without knowing the command
- Exit `0` for success, `1` for errors
- stdout for primary output, stderr for errors/warnings/progress messages
- Let a call raise and crash instead of wrapping it in `begin`/`rescue`. Only add explicit handling when the failure is actually likely or needs a clearer message than the default backtrace.

## Gems

When the script runs from inside a repository that has a Gemfile, add its gems to that Gemfile.

Otherwise, such as a skill script that runs from an installed copy of its plugin, declare them with inline Bundler so the script installs its own environment. Nothing else installs the gems, so when the Ruby version changes, the script crashes with a `LoadError`.

```ruby
require "bundler/inline"

gemfile do
  source "https://rubygems.org"
  gem "<gem-name>", "~> <major>.<minor>"
end
```

- Pin each gem to its current major version with `~>`. There's no lockfile, so a fresh install of an unpinned gem pulls the newest release, breaking changes included.
- Place the block before any `require` or `require_relative` that loads one of its gems.
- Use `gemfile`, not `gemfile(true)`. It installs missing gems quietly and skips the network when they're already installed.

## Required patterns

Always:

- `#!/usr/bin/env ruby` shebang
- `# frozen_string_literal: true` magic comment, after the shebang
- All error messages must start with `Error: ` and go to stderr via `warn`

Simple scripts:

- A top comment describing what the script does
- No `--help` flag
- If it takes an argument, print a usage message to stderr and exit `1` when the argument is missing

Complex scripts:

- `print_help` method for help output
- `--help` flag handled inside the `OptionParser` block
- Use `OptionParser` from the standard library for argument parsing
- Always call `print_help` when validation fails or unknown options are encountered
- Validate required flags after parsing completes
- Rescue `OptionParser::InvalidOption` and print `Error: The option <option> is invalid.`

Files in this skill

  • SKILL.md2.2 KB
  • assets/template-complex.rb1 KB
  • assets/template-simple.rb194 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.