import, import_relative, export
require 'carton' adds three private methods to Kernel, so they are callable from any file, in any Box. Signatures follow Carton’s own RBS in sig/carton.rbs.
import
Section titled “import”def import: (String path) -> untypedImports the Carton at path and returns its Export, or a Carton::Namespace for a Bare Carton.
pathis an absolute path, or a name searched on the current Box’s$LOAD_PATHlikerequire. The current directory is never checked.- A gem-shaped directory,
billing/lib/billing.rb, resolves to itslib/Entrypoint. - The first import of a Carton loads it in a new Carton Box. Later imports of the same Entrypoint, by any path, return the same value.
Raises:
LoadErrorwhen nothing matchespath.Carton::ImportErrorwhen Boxes are disabled,pathis in a Carton’s Interior, the import is circular, or a shared Gem Carton was built against other gem versions.
Billing = import 'billing'import_relative
Section titled “import_relative”def import_relative: (String path) -> untypedLike import, but resolves path relative to the calling file, like require_relative. It never falls back to $LOAD_PATH.
Billing = import_relative '../components/billing'export
Section titled “export”def export: [T] (T value) -> TDeclares the Carton’s Export and returns value. Only a call in the imported Entrypoint declares anything; in any other file, export checks its argument, returns it, and does nothing else.
- Takes exactly one value. Keywords export a plain Hash:
export version: '1.0'. - Raises
Carton::ExportErroron a second call in one Entrypoint, or for a Symbol. - Raises
ArgumentErrorwithout exactly one value.
export Billing