Reason #68 • March 9th, 2026

One global namespace

Many languages require explicitly declaring imports to access libraries or modules from other files or packages. A practical benefit is that it generates a sort of breadcrumb trail of all dependencies, disambiguating where a particular function or class is coming from. However, it also leads to a ton of boilerplate, and can allow for confusing naming situations where the thing imported is given a different name from its original name.

In Ruby, however, all classes and modules are defined in a single global namespace. This means that once a class or module (or indeed any constant) is defined, it can be accessed from anywhere in the program without further ado:

Ruby
# compressor.rb
require "zlib"

module Compressor
  def self.compress(data)
    Zlib::Deflate.deflate(data)
  end
end

# main.rb
require_relative "compressor"

# The Compressor module is defined, so we can access it:
compressed_data = Compressor.compress("Hello, world!")
# => "x\x9C\xF3H\xCD\xC9\xC9\xD7Q(\xCF/\xCAIQ\x04\x00 ^\x04\x8A"

# Zlib is also defined, so we can access that too:
uncompressed_data = Zlib::Inflate.inflate(compressed_data)
# => "Hello, world!"
      
JavaScript
// compressor.js
import zlib from "zlib";

export class Compressor {
  static compress(data) {
    return zlib.deflateSync(data);
  }
}

// main.js
import { Compressor } from "./compressor.js";

// We imported the Compressor class to access it:
const compressedData = Compressor.compress("Hello, world!");
// => <Buffer 78 9c f3 48 cd c9 c9 57 28 cf 2f ca 49 51 04 ...>

// We didn't import zlib, so we can't access it:
const uncompressedData = zlib.inflateSync(compressedData);
// => ReferenceError: zlib is not defined
      

If you're coming from a language with explicit imports, Ruby's global namespace might feel a bit chaotic at first, but it is a fundamental part of the language and what enables some of the most convenient and powerful features of the language, such as effortlessly referencing all loaded classes from an IRB session or modifying classes and methods after their initial definition ("monkey patching").

The most immediate benefit, though, is the death of all boilerplate, allowing us to focus our attention on code that actually does something.

Trust me, for those of us used to Ruby, it can feel absolutely excruciating to have to micro-manage imports all over the place when dabbling in other languages.

Ruby 4.0 and beyond: Box

Ruby 4.0 introduced a new experimental feature called Box, which provides a way to create isolated "boxes" of code where different sets of constants can be defined without interfering with each other.

As of yet, this isn't enabled by default and to be perfectly honest, I've never had any need for it. But I guess it remains to be seen if it will gain traction and if so, for what use cases.

History

The global namespace, as mentioned, is a fundamental part of what makes Ruby Ruby, and has been there since the very beginning.

In terms of inspiration, Smalltalk is notably also built around a single global "dictionary".