Skip to content

Commit

Permalink
load method
Browse files Browse the repository at this point in the history
  • Loading branch information
hasumikin committed Oct 30, 2023
1 parent 670db87 commit 6575a68
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions require.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ This page explains the loading external libraries feature introduced in 0.9.23.
## Description

CRuby loads external libraries using `Kernel.#require` method.
Likewise, PicoRuby has `require` method.
Likewise, PicoRuby has `require` and `load` method.
You can reuse a Ruby script by taking advantage of that.

## Gist

- Put your library files in the `/lib` directory in "PRK DRIVE"
- It may be easier to understand if you say `$LOAD_PATH` is `["/lib"]`
- The library file has to have `.rb` or `.mrb` extention. eg: `my_library.rb`
- `require` method ignores the extension, so just write `require "my_library"`
- `require` method supplements an extension, so just write `require "my_library"`
- `load` method only accepts a full path name. eg: `load "/path/to/my_library.rb"`
- `require` method does not load the same library more than once while `load` method does the library as many times as you call
- `.rb` file will be compiled into mruby VM code in microcontrller on the fly
- A large Ruby file is more likely to cause Out of Memory
- In such case, precompled mrb file will help
Expand Down

0 comments on commit 6575a68

Please sign in to comment.