Yes Thomas, as the error messages indicate, he gets this in Alex’s web-based Console Editor extension. Specifically when Alex’s console passes the code text to
I suggested the same test above 2 days ago.
EDIT: Just tested and everything works fine normally from the standard Ruby Console.
I put both files in a “alpha” subfolder of the “Plugins” folder, then loaded “beta.rb” …
And the last entry afterward in
$LOADED_FEATURES) is …
Kernel#require_relative works normally, without issues, and does not need the
"./" as Jim surmised above.
Kernel#require_relative first checks a path relative to the calling files path.
"./" does not help as the
"Plugins" path is not the current working directory, nor is the calling file’s path the current working directory.
BUT, there is also a catch to using
Kernel#require_relative. That is that it MUST be used from within a file, not from a console. It apparently NEEDS
__dir__ to be valid and non-
For example typing the following into the standard Ruby Console gives …
#=> Error: #<LoadError: cannot infer basepath>
#=> <main>:in `require_relative'
#=> <main>:in `<main>'
#=> SketchUp:1:in `eval'
The same errors for …
The only thing that does work from the Console, is using
Kernel#require and a path relative to any in the
$LOAD_PATH array …
Changed Topic Title to:
"Using require_relative from a Ruby console?"