I’ve seen a couple of people ask about why core extensions in Rails 3 are now extensions to the class. I haven’t had or heard of a clear enough answer so I tend to steer away. Until today.
I think this is a fantastic point. How else am I able to determine if a method is Ruby core or Rails core extension easily otherwise, without referencing the documentation? I can imagine that the core extensions were done this way to add to the speed of loading them, but again, I do not know the clear reason.
Could someone clarify as to why it was done this way rather than extending the classes with modules that are included? Thank you!
But overall to me this decision certainly makes sense since the
modules
which were created to store core extensions were kind of useless and
created deep nesting like ActiveSupport::CoreExtensions::String
obscuring the final purpose of exactly extending just String.
We'll be moving these to a single extension module per class rather
than directly reopening classes.
This preserves the ability to just require
'active_support/core_ext/string/inflections' without having to
manually include the module, without leading to a proliferation of
extensions in the class' ancestor chains.
Plus, it makes documentation extremely clear and easy to read. All the
string extensions in one place.
And, this allows users to override core methods without needing to
alias_method_chain the Active Support override. The AS extension can
just call super to pick it up.