diff options
| author | Koichi ITO <koic.ito@gmail.com> | 2025-12-21 23:14:22 +0900 |
|---|---|---|
| committer | Satoshi Tagomori <tagomoris@gmail.com> | 2026-01-04 12:52:40 +0900 |
| commit | d8d41d7441aabae5e5948f89cd759bbdc3bf5532 (patch) | |
| tree | ca5f6892c13e85f3b61fe8913cac8be0d3ae07fc /doc | |
| parent | 5064af7ed120b1d14ad5020ea39a4a6ff2a4a4ec (diff) | |
[DOC] Use `Ruby::Box#require_relative` in box.md examples
Based on the example, it appears that `foo.rb` and `main.rb` are expected to be in the same directory.
Since Ruby 1.9, the current directory is not included in `$LOAD_PATH` by default.
As a result, running `box.require('foo')` as shown in the sample code raises a `LoadError`:
```console
main.rb:2:in `Ruby::Box#require': cannot load such file -- foo (LoadError)
from main.rb:2:in `<main>'
```
To avoid this, it seems simplest to show either `box.require('./foo')` or `box.require_relative('foo')`.
In this PR, `box.require('foo')` is replaced with `box.require_relative('foo')` to make the intention of
using a relative path explicit.
This should reduce the chance that users trying Ruby Box will run into an unexpected error.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/language/box.md | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/doc/language/box.md b/doc/language/box.md index f2b59e5b39..4bbb70e529 100644 --- a/doc/language/box.md +++ b/doc/language/box.md @@ -117,7 +117,7 @@ Foo.foo.blank? #=> false # in main.rb box = Ruby::Box.new -box.require('foo') +box.require_relative('foo') box::Foo.foo_is_blank? #=> false (#blank? called in box) @@ -151,7 +151,7 @@ end # main.rb box = Ruby::Box.new -box.require('foo') +box.require_relative('foo') box::String.foo # NoMethodError ``` @@ -174,7 +174,7 @@ Array.const_get(:V) #=> "FOO" # main.rb box = Ruby::Box.new -box.require('foo') +box.require_relative('foo') Array.instance_variable_get(:@v) #=> nil Array.class_variable_get(:@@v) # NameError @@ -197,7 +197,7 @@ p $foo #=> nil p $VERBOSE #=> false box = Ruby::Box.new -box.require('foo') # "This appears: 'foo'" +box.require_relative('foo') # "This appears: 'foo'" p $foo #=> nil p $VERBOSE #=> false @@ -216,7 +216,7 @@ Object::FOO #=> 100 # main.rb box = Ruby::Box.new -box.require('foo') +box.require_relative('foo') box::FOO #=> 100 @@ -241,7 +241,7 @@ yay #=> "foo" # main.rb box = Ruby::Box.new -box.require('foo') +box.require_relative('foo') box::Foo.say #=> "foo" |
