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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

How do rubygems work anyway?

1 点作者 starrhorne超过 11 年前

1 comment

jamesbritt超过 11 年前
This doesn&#x27;t explain how rubygems works at all.<p>For example, when you do<p><pre><code> require &quot;some_gem&quot; </code></pre> how does <i>require</i> know where to find <i>some_gem.&lt;ext&gt;</i>?<p>First ruby looks in the current load path (i.e. <i>$:</i>). If it cannot find the file it then looks in your set of installed gems. If it finds a match it loads the file and adds that gem path to $:.<p><a href="http://ruby-doc.org/core-2.1.0/Kernel.html#method-i-require" rel="nofollow">http:&#x2F;&#x2F;ruby-doc.org&#x2F;core-2.1.0&#x2F;Kernel.html#method-i-require</a><p>(though those docs say nothing about checking the gem paths.)<p><i>This makes sense since if your project depends on a certain gem, who knows where you might reference it. Better load it as early as possible so its code can be used anywhere.</i><p>That&#x27;s silly. If you are referencing gem code in a file then have that file require the needed gem. <i>require</i> will only load the file once so you can wait until you need a gem before you load it.<p>(<i>load</i>, OTOH, will reload a file as often as you call it).