Hacker News new | ask | show | jobs
by pothibo 4681 days ago
Actually, rails overloads Ruby's autoload. So they do share some behavior. What rails does is it lets you only provide a module name and rails will try to find the path for you.

Also, the class reloading is done through ActionDispatch::Reloader. Those are middlewares (There's 3 of them by default IIRC).

I wrote about how it works and how you can use that to customize some of your code inside the app/ folder.

Shameless plug: http://pothibo.com/2013/07/namespace-stuff-in-your-app-folde...

1 comments

Rails does overload Ruby's autoload (naturally - no core functionality can remain un-monkeypatched. ;-)), but not for the on-demand autoloading the article describes, which is what most users contend with most frequently, and was what I most wanted to demystify. Thanks for the clarification though - I'll try to make the distinction clearer.
>>Rails does overload Ruby's autoload (naturally - no core functionality can remain un-monkeypatched. ;-))

Are you sure about that? To me it seems that if you pass a path to autoload, it does work like ruby STL https://github.com/rails/rails/blob/master/activesupport/lib...

Yep - if you pass a path the behaviour is as normal, but it's still overloaded to support the path inference behaviour. I guess it's not really monkeypatching though as `Module` itself is not modified, and you have to deliberately choose to use `ActiveSupport::Autoload`, so I reluctantly retract my parenthetical snark. :-)