TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Emulating Node.js Modules in Ruby

29 点作者 andrewnez超过 11 年前

4 条评论

__cyx超过 11 年前
My good friend and colleague Michel Martens has tried to propose this to the rubygem guys but unfortunately it was rejected because it&#x27;s not the `ruby way`.<p><a href="https://github.com/soveran/cargo" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;soveran&#x2F;cargo</a>
评论 #6578603 未加载
Argorak超过 11 年前
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:<p>#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.<p><a href="http://www.ruby-doc.org/core-2.0.0/Kernel.html#method-i-load" rel="nofollow">http:&#x2F;&#x2F;www.ruby-doc.org&#x2F;core-2.0.0&#x2F;Kernel.html#method-i-load</a><p>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 &quot;non-standard&quot; thing is just to high.
andrewnez超过 11 年前
The code for the importer is here: <a href="https://github.com/andrew/module_import" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;andrew&#x2F;module_import</a><p>It&#x27;s early days but could be quite an interesting way to handle dependencies in ruby.
parshap超过 11 年前
The module system is indeed one of the best things about Node. I&#x27;m not sure it fits well into all languages and their ecosystems, but it&#x27;s certainly interesting to try. For another example, here is an implementation for C: <a href="https://github.com/substack/dotc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;substack&#x2F;dotc</a>.