Ruby
// Write reliable Ruby avoiding mutable string traps, block pitfalls, and metaprogramming bugs.
$ git log --oneline --stat
stars:1,933
forks:367
updated:March 4, 2026
SKILL.mdreadonly
SKILL.md Frontmatter
nameRuby
slugruby
version1.0.1
descriptionWrite reliable Ruby avoiding mutable string traps, block pitfalls, and metaprogramming bugs.
metadata[object Object]
Quick Reference
| Topic | File |
|---|---|
| Mutable strings, object equality | objects.md |
| Proc vs lambda, return behavior | blocks.md |
| Visibility, method_missing | methods.md |
| Array/hash mutation traps | collections.md |
| define_method, eval traps | metaprogramming.md |
| ActiveRecord, N+1, callbacks | rails.md |
Critical Rules
- Strings are mutable —
s = "hi"; s << "!"; t = smeans t also has "!" ==vsequal?vseql?—==value,equal?identity,eql?hash equality- Default hash value is shared —
Hash.new([])shares same array, use block form returnin proc returns from enclosing method — use lambda for local return- Block variable shadows outer scope —
x = 1; [2].each { |x| }; xis still 1 (3.0+) method_missingwithoutrespond_to_missing?— breaksrespond_to?checksprivatein Ruby is per-object —self.private_methodfails, implicit receiver works||=doesn't work for false/nil distinction —false ||= truereplaces false- Frozen string literals —
# frozen_string_literal: truemakes strings immutable Symbol#to_proc—&:method_nameonly works with no-argument methodsrescue => ewithout type — catches StandardError, not Exceptionensurealways runs — even after return, use for cleanup