MΓ³dulo 23 Β· Design Patterns (All 23 GoF) β LecciΓ³n 1 de 23 Β· ~6 min
Singleton
Singleton: one shared instance for the whole app
Problem: you want exactly one instance of something β a Config, a shared Stripe client, a logger β and one global point to reach it.
PawWalk scenario: app configuration loaded once at boot. Every part of the API reads the same Config object; nobody should build a second one.
Ruby ships the pattern in the stdlib: require "singleton"; include Singleton makes .new private and gives you .instance.
Be honest: in Ruby a plain constant or a module of module-methods is usually enough. Reach for
Singletononly when you need lazy init plus a real object with state.