Complete AI TrainingYourJobSkills for your job

Skills / super-code

ruby

Language-specific super-code guidelines for ruby.

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

  1. [Enumerable & Collections](#enumerable)
  2. [Blocks, Procs & Lambdas](#blocks)
  3. [String Handling](#strings)
  4. [Error Handling](#errors)
  5. [Classes & Modules](#classes)
  6. [Ruby Idioms](#idioms)
  7. [Anti-patterns specific to Ruby](#antipatterns)

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-t

Subscribers only

The full skill, its 1 bundled files and every download is included with every paid Complete AI plan.

Details

Sourcecommunity
License
Risk labelsafe ("critical" means the skill may run commands or touch files — read before use)
FilesSKILL.md
Added2026-06-16

Related skills

bash

Language-specific super-code guidelines for bash.

c

Language-specific super-code guidelines for c.

cpp

Language-specific super-code guidelines for cpp.

csharp

Language-specific super-code guidelines for csharp.

dart

Language-specific super-code guidelines for dart.

elixir

Language-specific super-code guidelines for elixir.