Skip to content

Commit d8d41d7

Browse files
koictagomoris
authored andcommitted
[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.
1 parent 5064af7 commit d8d41d7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

doc/language/box.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Foo.foo.blank? #=> false
117117

118118
# in main.rb
119119
box = Ruby::Box.new
120-
box.require('foo')
120+
box.require_relative('foo')
121121

122122
box::Foo.foo_is_blank? #=> false (#blank? called in box)
123123

@@ -151,7 +151,7 @@ end
151151

152152
# main.rb
153153
box = Ruby::Box.new
154-
box.require('foo')
154+
box.require_relative('foo')
155155

156156
box::String.foo # NoMethodError
157157
```
@@ -174,7 +174,7 @@ Array.const_get(:V) #=> "FOO"
174174

175175
# main.rb
176176
box = Ruby::Box.new
177-
box.require('foo')
177+
box.require_relative('foo')
178178

179179
Array.instance_variable_get(:@v) #=> nil
180180
Array.class_variable_get(:@@v) # NameError
@@ -197,7 +197,7 @@ p $foo #=> nil
197197
p $VERBOSE #=> false
198198

199199
box = Ruby::Box.new
200-
box.require('foo') # "This appears: 'foo'"
200+
box.require_relative('foo') # "This appears: 'foo'"
201201

202202
p $foo #=> nil
203203
p $VERBOSE #=> false
@@ -216,7 +216,7 @@ Object::FOO #=> 100
216216

217217
# main.rb
218218
box = Ruby::Box.new
219-
box.require('foo')
219+
box.require_relative('foo')
220220

221221
box::FOO #=> 100
222222

@@ -241,7 +241,7 @@ yay #=> "foo"
241241

242242
# main.rb
243243
box = Ruby::Box.new
244-
box.require('foo')
244+
box.require_relative('foo')
245245

246246
box::Foo.say #=> "foo"
247247

0 commit comments

Comments
 (0)