Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you don't have a conflict, and the module is wrapping everything, nothing stops you from doing "include <yourmodule>".

Similarly, if you want to group modules that don't conflict together under a short module name, nothing stops you from doing:

    module MyGroup
      include Module1
      include Module2
      ...
    end
In other words, wrapping them doesn't remove your ability to use short non-namespaced names.

Using `include` of specific functionality into a class that will use it is furthermore an idiomatic way of avoiding that extra typing without polluting the global namespace

For that matter, you can often achieve close to what you're arguing for as well without actually making any changes to Ruby:

   def wrap_load(path) = class_eval(File.read(path), path)

   module Test
     # some_file.rb will act as-if defined within Test
     wrap_load("./some_file.rb")
   end
You can do better than that, to get closer to emulate `require` rather than `load`, and handle dependencies.

Overall, I think the fact you can do these things suggests you could probably write a good enough plug-in `require` monkeypatch suitable for the rare cases where `include` from within a class or module without needing a language extension.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: