Project

carton

0.0
The project is in a healthy, maintained state
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.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Carton

Carton logo

Easily box your Ruby

Carton is a thin wrapper around Ruby::Box for safe, ergonomic modularization in Ruby 4.0.6+. It gives you imports and exports that work like ES Modules while still feeling 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)
require 'carton'

MathTools = import_relative 'math'
MathTools::PI
MathTools.add(2, 3)

Docs

Development

bundle install                              # Install development deps
bundle exec rake format                     # Format code
bundle exec rake rubocop                    # Lint code
RUBY_BOX=1 ruby examples/minimal/main.rb     # Run the minimal example
RUBY_BOX=1 ruby examples/gems/main.rb        # Run the RubyGems example

Per-Carton Bundler setup and path-gem imports work on Ruby 4.0.6. RUBY_BOX=1 bundle exec still fails when a Gemfile evaluates a gemspec.

License

Available as open source under the MIT License.