I disagree with a couple of things in the extensions page.
Firstly, I feel that crossing out the word "monkeypatch" and having "hack" as a crossed-out term also makes the document a little personal. This should be an educational document and any personal vendettas you have against this coding style should be explained in a neutral tone with clear examples of why it is bad or when it is bad. Sometimes it's a Necessary Evil.
Secondly, I view this line as a hack:
Dir[File.expand_path("../../../lib/extruby/**/*.rb", __FILE__)].each { |f| require f }
Honestly, I was going to suggest adding the lib/extruby
dir to the autoload_paths
for the application (in config/application.rb
) but that wouldn't work, as many of the constants you are "extending" are already loaded, and so it will not attempt to autoload them.
Anyway, I would rather this be put here:
Dir[Rails.root + "lib/extruby/**/*.rb"].each { |f| require f }
This is much cleaner (no relative paths) and reads much better.
Thirdly, you should be more explicit in this sentence for point #2 of your "Considerations" sub-section:
It prefixes the initializer with _ causing the initializer to be loaded before any initializer, making the extensions available as soon as possible.
It will not be loaded before any initializer, because if I had an initializer called _do_something.rb
that initializer would be run first! You should write that initializers are run in alphabetical ordering and by prefixing this initializer with an underscore we make it run first.