Skip to content
dtcristoPublic

About

Easily box your Ruby

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

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.

About

Easily box your Ruby

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages