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/orat 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
curlorgrepin Rugo. Shell out for what the shell does best, then process results in Rugo. - Test where you code. Inline
ratsblocks 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 accessperson.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" ... endblocks, run withrugo rats - Internal fields:
__double_underscore__convention for private state
Converted and distributed by TomeVault — claim your Tome and manage your conversions.