Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
require_realative calls self.require instead of Kernel.require #4053
jruby 220.127.116.11 (2.2.3) 2016-01-26 7bee00d Java HotSpot(TM) 64-Bit Server VM 25.91-b14 on 1.8.0_91-b14 +jit [linux-amd64]
Originally discovered by test run on Travis CI: https://travis-ci.org/lasso/racket/jobs/149817357
When running main.rb (attached) using MRI, the version string '0.5.0' is printed.
When running main.rb (attached) using JRuby, an error is thrown (because Foo.require is called).
A simple workaround that worked for me was using Kernel.require_relative instead of of require_relative in the Foo.version method, then JRuby uses Kernel.require instead of Foo.require.
In summary MRI (and Rubinius) always calls Kernel.require from Kernel.require_relative, but JRuby seems to use self.require if available.
The main difference between JRuby and other implementations seems to be that JRuby is the only one that is defining require_relative on the "ruby" side (thus following ruby rules). Other implementations have custom (internal) classes/functions to require_files.
MRI uses internal C functions: https://github.com/ruby/ruby/blob/c3ceb1bff26a0dc59d7b93647e3a58c57e7c0440/load.c#L833
Rubinius uses an internal class called CodeLoader: https://github.com/rubinius/rubinius/blob/2bf206d50c0fb1916e17d936de2e7a4c2a42145b/core/code_loader.rb#L138
JRuby uses the public Kernel class:
@lasso sounds like JRuby might do a "better" Ruby job here :) ... suppose you wanted to override
@kares - I agree that JRuby does a better job not "special casing" methods in Kernel, but in my code I overrode