From: Xavier Noria Date: 2018-12-27T07:36:43+01:00 Subject: [ruby-core:90741] possible bug with hacked autoload path and classes/modules --===============1219504053== Content-Type: multipart/alternative; boundary="000000000000a86ed1057dfb2d11" --000000000000a86ed1057dfb2d11 Content-Type: text/plain; charset="UTF-8" Hey, I am experimenting with decorated Kernel#require and hacked paths, and while everything works as expected, this use case doesn't: module Kernel alias original_require require def require(path) if path == "hacked" original_require("user") else original_require(path) end end end Object.autoload(:User, "hacked") User In user.rb we have "class User; end" and the error message is uninitialized constant User (NameError) Did you mean? User Note that we are suggested User! If "user.rb" contains "User = 1" or "User = Class.new", no problem. Also, it is interesting that if we define the autoload in the decoration again: module Kernel alias original_require require def require(path) if path == "hacked" Object.autoload(:User, "user") original_require("user") else original_require(path) end end end Object.autoload(:User, "hacked") User it works fine too, the User class is loaded. Could that be a bug in the autoload code triggered by the class/module keywords? --000000000000a86ed1057dfb2d11 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
He= y, I am experimenting with decorated Kernel#require and hacked paths, and w= hile everything works as expected, this use case doesn't:
=C2=A0 module K= ernel
=C2=A0=C2=A0=C2=A0 alias original_require require
=C2=A0=C2=A0= =C2=A0 def require(path)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if path =3D=3D &= quot;hacked"
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 original_re= quire("user")
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 else
=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 original_require(path)
=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 end
=C2=A0=C2=A0=C2=A0 end
=C2=A0 end

=C2=A0 O= bject.autoload(:User, "hacked")
=C2=A0 User


In user.rb we have "class User; end" and the er= ror message is

=C2=A0 uninitialized constant User (NameError)
=C2=A0 Did you mean?=C2= =A0 User

Note that we are suggested User!

If "user.rb" contains "User =3D 1&qu= ot; or "User =3D Class.new", no problem.

Also, it is interesting that if we define the autoload in the decorat= ion again:

=C2=A0 module Kernel
=C2=A0=C2=A0=C2=A0 alias original_require = require
=C2=A0=C2=A0=C2=A0 def require(path)
=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 if path =3D=3D "hacked"
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 Object.autoload(:User, "user")
=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 original_require("user")
=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 else
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 origi= nal_require(path)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 end
=C2=A0=C2=A0=C2= =A0 end
=C2=A0 end

=C2=A0 Object.autolo= ad(:User, "hacked")
=C2=A0 User

it works fine too, the User class is loaded.

<= div>Could that be a bug in the autoload code triggered by the class/module = keywords?



--000000000000a86ed1057dfb2d11-- --===============1219504053== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline Unsubscribe: --===============1219504053==--