ruby
What it does
This guide helps Ruby programmers write cleaner and more efficient code. It shows how to use the language's built-in tools to accomplish tasks more simply and quickly.
When to use it
- βWhen you want your Ruby code to be easier to read.
- βWhen learning best practices for writing Ruby code.
- βTo optimize the performance of your Ruby code.
Skill link
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/ruby/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βHow can I write more idiomatic Ruby code for grouping items?β
5 new skills a week. 1 minute to read.
How it works
The AI compares 'bad' code examples with 'good' Ruby examples. It suggests using specific language methods that get the job done more concisely and efficiently.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Ruby: Idiomatic Efficiency Reference
When to Use
- Use this skill when the task matches this description: Language-specific super-code guidelines for ruby.
Table of Contents
- Enumerable & Collections
- Blocks, Procs & Lambdas
- String Handling
- Error Handling
- Classes & Modules
- Ruby Idioms
- Anti-patterns specific to Ruby
1. Enumerable & Collections {#enumerable}
# β Manual accumulation
result = []
items.each do |item|
result << item.name.upcase if item.active?
end
# β
result = items.select(&:active?).map { |i| i.name.upcase }
# β Manual grouping
grouped = {}
items.each do |item|
grouped[item.category] ||= []
grouped[item.category] << item
end
# β
grouped = items.group_by(&:category)
# β Manual sum
total = 0
orders.each { |o| total += o.amount }
# β
total = orders.sum(&:amount)
# β Checking existence then accessing
if hash.key?(key)
value = hash[key]
end
# β
value = hash[key] # returns nil if missing
# or with default:
value = hash.fetch(key, default_value)
# or raising on missing:
value = hash.fetch(key) # raises KeyError
Prefer map/select/reject/sum over manual loops. Use &:method for single-method blocks.
2. Blocks, Procs & Lambdas {#blocks}
# β Explicit block-to-proc conversion when unnecessary
items.map { |item| item.to_s }
# β
items.map(&:to_s)
# β Proc.new when lambda is safer (arity check + return behavior)
handler = Proc.new { |x| x * 2 }
# β
handler = ->(x) { x * 2 }
# β Multi-line block with { }
items.map { |item|
result = transform(item)
validate(result)
result
}
# β
β do/end for multi-line, { } for single-line
items.map do |item|
result = transform(item)
validate(result)
result
end
3. String Handling {#strings}
# β String concatenation in loop
result = ""
items.each { |i| result += i.name + ", " }
# β
result = items.map(&:name).join(", ")
# β String concatenation for assembly
greeting = "Hello, " + name + "! You have " + count.to_s + " messages."
# β
greeting = "Hello, #{name}! You have #{count} messages."
# β Mutable string where frozen is fine (Ruby 3+ encourages frozen)
SEPARATOR = ", "
# β
SEPARATOR = ", ".freeze
# or add `# frozen_string_literal: true` at file top
Use heredocs (<<~HEREDOC) for multi-line strings. <<~ strips indentation.
4. Error Handling {#errors}
# β Rescuing Exception (catches EVERYTHING including SignalException, SystemExit)
begin
risky
rescue Exception => e
log(e)
end
# β
β rescue StandardError (the default)
begin
risky
rescue StandardError => e
log(e)
raise
end
# or just: rescue => e (same as StandardError)
# β Using rescue as flow control
begin
value = hash.fetch(key)
rescue KeyError
value = default
end
# β
value = hash.fetch(key, default)
# β Inline rescue hiding errors
result = dangerous_operation rescue nil
# β
β inline rescue only for truly trivial fallbacks
result = Integer(input) rescue nil # acceptable for parsing
5. Classes & Modules {#classes}
# β Manual accessors
class User
def name
@name
end
def name=(value)
@name = value
end
end
# β
class User
attr_accessor :name
end
# β Deep inheritance for shared behavior
class Animal; end
class Pet < Animal; end
class Dog < Pet; end
# β
β mixins for shared behavior, inheritance for "is-a"
module Trainable
def train = puts("Training #{name}")
end
class Dog
include Trainable
attr_reader :name
def initialize(name) = @name = name
end
# β Class with only class methods (namespace via class)
class MathUtils
def self.square(x) = x * x
def self.cube(x) = x ** 3
end
# β
module MathUtils
module_function
def square(x) = x * x
def cube(x) = x ** 3
end
6. Ruby Idioms {#idioms}
# β Explicit boolean return
def active?
if status == :active
true
else
false
end
end
# β
def active? = status == :active
# β nil check before method call
if user && user.name
puts user.name
end
# β
(Ruby 2.3+)
puts user&.name if user&.name
# or with safe navigation:
user&.name&.then { |n| puts n }
# β Conditional assignment verbosely
if @cache.nil?
@cache = expensive_compute
end
# β
@cache ||= expensive_compute
β¦
FAQ
What does 'idiomatic' mean in programming?
It means writing code that follows the conventions and style expected by the programming community for a specific language, making it feel more natural and easier for others to understand.
Why is it important to use methods like `map` and `select` instead of manual loops?
These methods are generally shorter, more readable, and less error-prone than writing loops manually. They can also be more efficient.
What are 'anti-patterns'?
These are common coding approaches that seem to work but actually lead to more complex, harder-to-maintain, or inefficient code. The guide shows how to avoid them.
Details
Original description by the author
Language-specific super-code guidelines for ruby.
Popularity
- GitHub stars
- 48k
- Ranking position
- #5897
- License
- MIT
- Updated
- 10/15/2026
Comments
- β¦
More skills from this repository
00-andruia-consultant
48kHelps your agent start or improve AI projects. It analyzes code, suggests tools, and creates action plans in Spanish.
007
48kLets your agent perform security audits and threat modeling. It's useful for protecting projects against attacks and vulnerabilities.
10-andruia-skill-smith
48kHelps your agent create or improve AI tools. It defines how tools work, writes documentation, and validates the structure.
20-andruia-niche-intelligence
48kLets your agent create a summary about a specific industry. It's useful for understanding the context, rules, usage patterns, and risks of a project, using reliable sources.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.