Only exports cross
Other Cartons get the export, not your constants, methods, or imports.
# billing.rb
TAX_RATE = 10
# main.rb
TAX_RATE # NameError
Real boundaries for Ruby
Ruby apps draw boundaries with folders and namespaces. Ruby ignores them. Carton makes them real. Only a Carton's export crosses, enforced at runtime.
gem install cartonmain.rb
require 'carton'
Billing = import_relative 'billing'
Billing.invoice(100) # => 110
Tax # NameError: billing's importbilling Carton
billing.rb
Tax = import_relative 'tax'
module Billing
def self.invoice(total) = total + Tax.on(total)
end
export Billingtax Carton
tax.rb
module Tax
def self.on(total) = total / 10
end
export TaxOpen classes and global constants are great until the app gets big. Then a money helper in Billing changes what Shipping prints.
Linters miss what they can't parse. Services turn method calls into network calls. Carton draws the boundaries inside one process.
billing/core_ext.rb
class Integer
def to_s = '$%.2f' % (self / 100.0)
endshipping/label.rb
"Box #{3} of #{4}"
# => "Box $0.03 of $0.04"shipping/ship.rb
Billing::Ledger.post(order) # internalsGemfile.lock
faraday (1.10.6) # Billing wants 2.xOther Cartons get the export, not your constants, methods, or imports.
# billing.rb
TAX_RATE = 10
# main.rb
TAX_RATE # NameErrorActiveSupport's String#blank? applies only in the Carton that loads it.
# billing.rb
''.blank? # => true
# main.rb
''.blank? # NoMethodErrorEach Carton can bring its own bundle and gem versions.
# billing/Gemfile.lock
faraday (2.15.0)
# shipping/Gemfile.lock
faraday (1.10.6)Export a module from one file and import it from another. Carton is experimental and needs Ruby 4.0.7+ with RUBY_BOX=1.