Carton
Easily box your Ruby
Carton is a thin wrapper around Ruby::Box for safe, ergonomic modularization in Ruby 4+. It gives you imports and exports that feel like ES Modules while still reading like Ruby. Each carton can isolate constants, gems, and monkey patches behind a small public API, so large apps can keep clear boundaries.
Minimal usage
# user.rb
class User
def initialize(name) = @name = name
end
export_default User
# main.rb
require 'carton'
User = import_relative 'user'
alice = User.new('Alice')
Named exports return a namespace-like module:
# math.rb
def add(a, b) = a + b
export PI: 3.14159, add: method(:add)
MathTools = import_relative 'math'
MathTools::PI
MathTools.add(2, 3)
Docs
- USAGE.md - detailed import/export, load path, and Bundler usage
- DESIGN.md - implementation overview and constraints
- TODO.md - future improvements and Bundler upstream ideas
- examples/minimal/README.md - smallest example
- examples/complex/README.md - multi-carton example
Development
bundle install # Install development deps
RUBY_BOX=1 bundle exec rake # Run all tests and examples
bundle exec rake format # Format code
License
Available as open source under the MIT License.