It seems like a common problem in Ruby applications in typical long-running process environments such as the rails server
, that class-reloading to ease development pain is a difficult, but important problem to solve.
It strikes me that the language knows best what constants are defined by the stdlib, and is perfectly placed to know what constants were loaded from what files and when, and of course to offer to re-load them.
There are come complex cases where by require 'foo'
, you also define Bar
, but that isn't too challenging to track, and furthermore cases where define_const
has been used also muddy things up. Threaded loading is yet another problem, but I can really see a case for allowing threads to re-load themselves from the current state of the disk's files. (Faster test server would be #1 thought)
It seems like it should be a language feature, and not something that many, many different people need to roll solutions for.
So in summary, why is it that this isn't a language feature? It seems like it should be, although the usage profile is almost exclusively limited to long running dev servers.
The other question here could be "why doesn't Rails use a built-in DRB model for making the dev server fast, and skip all the class reloading", that's also an interesting discussion, but not for now.