From: Intransition Date: 2013-01-09T07:54:44+09:00 Subject: Re-implementing Autoload ------=_Part_1341_3585519.1357685681155 Content-Type: multipart/alternative; boundary="----=_Part_1342_31624501.1357685681155" ------=_Part_1342_31624501.1357685681155 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Finally accepting the fact that autoload will never be fixed (i.e. there it no way to override require to effect autoload's behavior) I decided to try re-implementing autoload in Ruby itself. So here's what I arrived at: https://github.com/rubyworks/autoload/blob/master/lib/autoload.rb I thought that was it, but then I tried a `bundle exec` call with this autoload.rb loaded (via RUBYOPT), and it bombs. autoload.rb:104:in `const_missing': uninitialized constant Module::Settings (NameError) from /home/trans/.gem/ruby/1.9.3/gems/bundler-1.2.3/lib/bundler.rb:191:in `settings' from /home/trans/.gem/ruby/1.9.3/gems/bundler-1.2.3/lib/bundler.rb:330:in `configure_gem_home_and_path' from /home/trans/.gem/ruby/1.9.3/gems/bundler-1.2.3/lib/bundler.rb:86:in `configure' from /home/trans/.gem/ruby/1.9.3/gems/bundler-1.2.3/lib/bundler.rb:142:in `definition' from /home/trans/.gem/ruby/1.9.3/gems/bundler-1.2.3/lib/bundler/cli.rb:423:in `exec' from /home/trans/.gem/ruby/1.9.3/gems/bundler-1.2.3/lib/bundler/vendor/thor/task.rb:27:in `run' from /home/trans/.gem/ruby/1.9.3/gems/bundler-1.2.3/lib/bundler/vendor/thor/invocation.rb:120:in `invoke_task' from /home/trans/.gem/ruby/1.9.3/gems/bundler-1.2.3/lib/bundler/vendor/thor.rb:275:in `dispatch' from /home/trans/.gem/ruby/1.9.3/gems/bundler-1.2.3/lib/bundler/vendor/thor/base.rb:408:in `start' from /home/trans/.gem/ruby/1.9.3/gems/bundler-1.2.3/bin/bundle:14:in `block in ' from /home/trans/.gem/ruby/1.9.3/gems/bundler-1.2.3/lib/bundler/friendly_errors.rb:4:in `with_friendly_errors' from /home/trans/.gem/ruby/1.9.3/gems/bundler-1.2.3/bin/bundle:14:in `' from /home/trans/.gem/ruby/1.9.3/bin/bundle:23:in `
' Turns out that the `self` in const_missing that causes this is `#`. How can I workout the `Bundler` namespace given that? All other advice on improving this is also appreciated. ------=_Part_1342_31624501.1357685681155 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Finally accepting the fact that autoload will never be fixed (i.e. the= re it no way to override require to effect autoload's behavior) I decided t= o try re-implementing autoload in Ruby itself.

So here's what I arrived at:

    = https://github.com/rubyworks/autoload/blob/master/lib/autoload.rb

I thought that was it, but then I tried a `bundle exec= ` call with this autoload.rb loaded (via RUBYOPT), and it bombs.
=
    autoload.rb:104:in `const_missing': unini= tialized constant Module::Settings (NameError)
=09from /home/trans/.gem/ruby= /1.9.3/gems/bundler-1.2.3/lib/bundler.rb:191:in `settings'
=09from /home/tra= ns/.gem/ruby/1.9.3/gems/bundler-1.2.3/lib/bundler.rb:330:in `configure_gem_= home_and_path'
=09from /home/trans/.gem/ruby/1.9.3/gems/bundler-1.2.3/lib/bu= ndler.rb:86:in `configure'
=09from /home/trans/.gem/ruby/1.9.3/gems/bundle= r-1.2.3/lib/bundler.rb:142:in `definition'
=09from /home/trans/.gem/ruby/1.9= .3/gems/bundler-1.2.3/lib/bundler/cli.rb:423:in `exec'
=09from /home/trans/.= gem/ruby/1.9.3/gems/bundler-1.2.3/lib/bundler/vendor/thor/task.rb:27:in `ru= n'
=09from /home/trans/.gem/ruby/1.9.3/gems/bundler-1.2.3/lib/bundler/vendor= /thor/invocation.rb:120:in `invoke_task'
=09from /home/trans/.gem/ruby/1.9.3= /gems/bundler-1.2.3/lib/bundler/vendor/thor.rb:275:in `dispatch'
= =09from /ho= me/trans/.gem/ruby/1.9.3/gems/bundler-1.2.3/lib/bundler/vendor/thor/base.rb= :408:in `start'
=09from /home/trans/.gem/ruby/1.9.3/gems/bundler-1.2.3/bin/b= undle:14:in `block in <top (required)>'
=09from /home/trans/.gem/ruby/= 1.9.3/gems/bundler-1.2.3/lib/bundler/friendly_errors.rb:4:in `with_friendly= _errors'
=09from /home/trans/.gem/ruby/1.9.3/gems/bundler-1.2.3/bin/bundle:1= 4:in `<top (required)>'
=09from /home/trans/.gem/ruby/1.9.3/bin/bun= dle:23:in `<main>'

Turns out that = the `self` in const_missing that causes this is `#<Class:Bundler>`. H= ow can I workout the `Bundler` namespace given that?

All other advice on improving this is also appreciated.



------=_Part_1342_31624501.1357685681155-- ------=_Part_1341_3585519.1357685681155--