News for hackers. Stuff that matters.
Re:Emulating Node.js Modules in Ruby by __cyx on Saturday October 19, 2013 @06:54PM (#6578267)
My good friend and colleague Michel Martens has tried to propose this to the rubygem guys but unfortunately it was rejected because it's not the `ruby way`.

https://github.com/soveran/cargo

Re:Emulating Node.js Modules in Ruby by andrewnez on Saturday October 19, 2013 @09:03PM (#6578603)
Ah that's really interesting, I've added it to the bottom of the post as a note.
Re:Emulating Node.js Modules in Ruby by Argorak on Saturday October 19, 2013 @04:22PM (#6577652)
I am not sure whether this is a good approach, given how much module hierarchy matters in ruby. I came up with similar hacky things as the OP. I played around with ideas a few years ago and found an interesting gem:

#load actually allows you to load against an anonymous module to protect the global namespace. It would be interesting to provide a non-anonymous module there.

http://www.ruby-doc.org/core-2.0.0/Kernel.html#method-i-load

In the end, I found that deviating from such a fundamental part of the language to be less worthwhile than expected. The cognitive load of doing the "non-standard" thing is just to high.

Re:Emulating Node.js Modules in Ruby by andrewnez on Saturday October 19, 2013 @03:33PM (#6577505)
The code for the importer is here: https://github.com/andrew/module_import

It's early days but could be quite an interesting way to handle dependencies in ruby.

Re:Emulating Node.js Modules in Ruby by parshap on Saturday October 19, 2013 @06:19PM (#6578141)
The module system is indeed one of the best things about Node. I'm not sure it fits well into all languages and their ecosystems, but it's certainly interesting to try. For another example, here is an implementation for C: https://github.com/substack/dotc.