Zeitwerk outside of rails

From wikinotes

In Gems

initializing zeitwerk

# my-project/lib/my_project.rb

# load gems that may not load otherwise (ex.)
require "sorbet-runtime"
require "active_support/all"

# load zeitwerk
require "zeitwerk"
loader = Zeitwerk::Loader.for_gem
loader.enable_reloading
loader.setup
loader.eager_load

# define your root module
module MyProject
end

console stubs

ruby irb, ruby pry and other consoles may not automatically (or properly) load zetiwerk.
you may want to create a stub

# my-project/bin/console
#!/usr/bin/env ruby

require "bundler/setup"
require "my_project"

require "irb"
IRB.start(__FILE__)