Inline Script Dependencies
As part of my day job building out a developer platform, I do a lot of prototyping and testing. These are often multi-step workflows, with an end user’s browser involved to boot (we do a lot of auth stuff).
I find myself first reaching for Ruby here for several reasons:
- Ruby is a comfy language for me.
- Ruby’s standard library… exists (looking at you JavaScript), and built-in types come with loads of utility.
- And finally—the main thing I wanted to write about—you can inline the script’s dependencies.
More on that last piece.
Inline Bundler
Pretty quickly, I’ll need some third-party gem for the task. For example, maybe
I’m standing up a quick web-server that implements a new
/.well-known endpoint I want to prototype against. Bundler makes
this so easy:
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "puma"
gem "rackup"
gem "sinatra"
gem "sinatra-contrib"
end
get "/.well-known/oauth-protected-resource" do
json resource: "https://example.com/resource",
authorization_servers: ["https://auth.example.com"],
bearer_methods_supported: ["header"]
end
Paste that into a .rb file, run it with ruby, and you’re off to the races.
Gems are installed somewhere in the background automagically.
I find this pattern really lowers the barrier to experimentation. Of course, we live in the era of AI, where that barrier has already been steadily dropping. But even here, small and focused files play well with a coding agent’s limited context window.
Elsewhere
I wish more tools embraced this pattern. The few I know of:
- Nix and
nix-shellas a shebang can do this, and it’s even language agnostic. uvfor Python similarly can parse dependencies from a magic comment. The Astral folks are doing amazing work.
Node is the main place I’d like to see this pattern supported, since I spend much of my time these days writing JavaScript and TypeScript (though I think ESM imports with Deno may “just work”).
Anyway, hopefully this nudges you (or your agent) toward writing more scripts that do more than you’d normally expect.