I have been using the Rails console a fair bit lately and its making me curious. Commands like
>> app.get("/")
=> 200
>> app.html_document.to_s
make me curious about how does Rails works in memory. Can anyone explain what’s going in there? What objects are getting instantiated when and when do they get destroyed?
After a little time and a lot of reading, here is a minimal answer to my own question since this is still being viewed by a steady trickle of people. Keep in mind that I am still new to Rails and this is simply my understanding of it after about two months of working with it.
What get instantiated when is effected by your environment settings because class loading (among other things) is handled quite differently in development vs production. The bare essentials can be gleaned from reading the comments the files in config/environments/
and
Aside from that, general flow is illustrated in all the typical MVC diagrams (dispatcher > controller > model > controller > view ) and while true, there are tonnes of other classes instantiated along the way. An exhaustive list would be exactly that, exhausting.
For those interested in the details (at least all the details that matter) but not sure where to go, the book “The Rails Way” by Obie Fernandez is very worthwhile and deals with this rather extensively.