| name | idiomatic-rugo |
| description | Guide to writing clean, idiomatic Rugo code. Load when writing .rugo scripts, reviewing Rugo code style, or learning Rugo patterns and best practices. |
Idiomatic Rugo
A guide to writing clean, expressive Rugo code. Rugo borrows Ruby's elegance, Go's compilation speed, and Bash's street smarts — compiled to native binaries.
This skill covers idioms and patterns that experienced Rugo programmers reach for instinctively. Each chapter is available as a detailed reference.
Chapters
- Expressive Basics — String interpolation, paren-free calls, constants, heredocs, and raw strings.
- Collections with Character — Hashes as lightweight objects, dot access, the factory pattern, array idioms, and iteration.
- Functions and Lambdas — First-class functions, closures, higher-order patterns, dispatch tables, and composition.
- Graceful Failure — The three levels of
try/or, raising errors, and building resilient code.
- Shell Power — Shell fallback, backtick capture, the pipe operator, and mixing paradigms.
- Concurrent Thinking — Spawn, parallel, timeouts, and task polling.
- Structuring Your Code — Structs, modules, the Go bridge, and type introspection.
- Patterns in the Wild — Data pipelines, builder pattern, inline tests, and lessons from real libraries.
The Rugo Philosophy
- Start simple. Hashes before structs. Functions before classes. Graduate to more structure only when needed.
- Be explicit about failure. Use
try/or at the right level. Don't let errors propagate silently, and don't panic unnecessarily.
- Compose small pieces. Collection methods, lambdas, and closures combine into powerful patterns without complex abstractions.
- Use the shell. Don't rewrite
curl or grep in Rugo. Shell out for what the shell does best, then process results in Rugo.
- Test where you code. Inline
rats blocks keep tests and implementation together. Use them.
Quick Reference
- Interpolation:
"Hello, #{name}!" — any expression inside #{}
- Constants: Uppercase start → assigned once:
PI = 3.14
- Hash objects:
{name: "Alice", age: 30} with dot access person.name
- Factory pattern: Functions returning hashes with lambda methods
- Error handling:
try expr / try expr or default / try expr or err ... end
- Shell capture:
user = `whoami`
- Pipes:
echo "hello" | str.upper | puts
- Concurrency:
spawn expr + .value / parallel ... end
- Imports:
use "http" (stdlib) / import "strings" (Go) / require "file" (user)
- Collection pipelines:
.filter(fn(x) ... end).map(fn(x) ... end).join(", ")
- Inline tests:
rats "name" ... end blocks, run with rugo rats
- Internal fields:
__double_underscore__ convention for private state