ruby-style: prefer Pathname over File for path manipulation
Add a new "File and path operations" section that prefers Pathname
for dirname/extname/expand_path-style operations, using the / operator
for joining. File is still fine for read/write/open.
Assisted-by: Owl Alpha via pi
diff --git a/ai/skills/ruby-style/SKILL.md b/ai/skills/ruby-style/SKILL.md
index 90741e5c..6b17e95b 100644
--- a/ai/skills/ruby-style/SKILL.md
+++ b/ai/skills/ruby-style/SKILL.md
@@ -65,7 +65,7 @@ items.each do |item|
log(item)
end
-File.open(path) do |f|
+Pathname.new(path).open do |f|
f.write(data)
end
@@ -76,6 +76,28 @@ items.each { |item| process(item) }
names = items.map do |item| item.name end
```
+## File and path operations
+
+Prefer `Pathname` over `File` for path manipulation. `Pathname` is
+object-oriented, composable, and works well with the rest of the
+stdlib.
+
+```ruby
+# good
+path = Pathname.new("/app/config/database.yml")
+path.dirname
+path.extname
+path / ".." / "secrets.yml"
+
+# bad — procedural and harder to chain
+File.dirname("/app/config/database.yml")
+File.extname("/app/config/database.yml")
+File.expand_path("../secrets.yml", "/app/config/database.yml")
+```
+
+Use `File` only for the operations that don't have a `Pathname`
+equivalent (`File.read`, `File.write`, `File.open` with a block).
+
## Building hashes
Prefer `.to_h` with a block over `.each_with_object` or manual