'require'看起来和'Gem.available'之间有什么区别?(What is the difference between where '

编程入门 行业动态 更新时间:2024-10-25 05:11:33
'require'看起来和'Gem.available'之间有什么区别?(What is the difference between where 'require' looks and where 'Gem.available?' looks for gems?)

关于路径如何与宝石一起工作,我有点困惑。 这是我困惑的核心:

>> require 'rubygems' => false >> Gem.available?('money') => true >> require 'money' LoadError: no such file to load -- money from (irb):3:in `require' from (irb):3 from /usr/bin/irb:12:in `<main>' >> Gem.available?('pony') => false >> require 'pony' => true

这是由irb 0.9.5(05/04/13)运行这是特别令人困惑的,因为gem list --local收益率:

*** LOCAL GEMS *** albino (1.0) bcat (0.5.2) builder (2.1.2) bundler (1.0.0) classifier (1.3.3) diff-lcs (1.1.2) directory_watcher (1.3.2) fast-stemmer (1.0.0) gdata (1.1.1) gdata2 (0.1) github-markup (0.5.0) gollum (1.0.1) google4r-checkout (1.0.6.1) grit (2.2.0) jekyll (0.7.0) kwalify (0.7.1) liquid (2.2.2) maruku (0.6.0) mime-types (1.16) mocha (0.9.8) money (3.0.5) mustache (0.11.2) nokogiri (1.4.3.1) rack (1.2.1, 1.1.0) rake (0.8.7) rubygems-update (1.3.7) sanitize (1.2.1) sinatra (1.0) syntax (1.0.0) unicorn (1.1.3)

其中特别包含 money但不包括 pony 。

这是gem env的输出:

RubyGems Environment: - RUBYGEMS VERSION: 1.3.7 - RUBY VERSION: 1.9.1 (2010-01-10 patchlevel 378) [x86_64-linux] - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.9.1 - RUBY EXECUTABLE: /usr/bin/ruby1.9.1 - EXECUTABLE DIRECTORY: /usr/bin - RUBYGEMS PLATFORMS: - ruby - x86_64-linux - GEM PATHS: - /usr/lib/ruby/gems/1.9.1 - /home/aresnick/.gem/ruby/1.9.1 - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :benchmark => false - :backtrace => false - :bulk_threshold => 1000 - REMOTE SOURCES: - http://rubygems.org/

如果不清楚, gem和ruby使用相同的红宝石,即:

aresnick@dror:~$ which ruby /usr/bin/ruby aresnick@dror:~$ ls -al $(which ruby) lrwxrwxrwx 1 root root 22 2010-08-28 20:08 /usr/bin/ruby -> /etc/alternatives/ruby aresnick@dror:~$ ls -al /etc/alternatives/ruby lrwxrwxrwx 1 root root 18 2010-08-28 20:08 /etc/alternatives/ruby -> /usr/bin/ruby1

我怀疑问题在于正在查看的路径,特别是因为我可以和不能访问的其他宝石,例如gdata不可用而sinatra是。 。 。

aresnick@dror:~$ gem which pony /var/lib/gems/1.9.1/gems/pony-1.0/lib/pony.rb aresnick@dror:~$ gem which money /usr/lib/ruby/gems/1.9.1/gems/money-3.0.5/lib/money.rb aresnick@dror:~$ gem which sinatra /var/lib/gems/1.9.1/gems/sinatra-1.0/lib/sinatra.rb aresnick@dror:~$ gem which gdata /usr/lib/ruby/gems/1.9.1/gems/gdata-1.1.1/lib/gdata.rb aresnick@dror:~$ irb >> require 'sinatra' => true >> require 'gdata' LoadError: no such file to load -- gdata from (irb):2:in `require' from (irb):2 from /usr/bin/irb:12:in `<main>'

所以,我认为没有找到/usr/lib/ruby/gems/1.9.1宝石,而/var则是。 我确定用符号链接可以解决这个问题,但我想知道a)为什么会发生这种情况并且b)这些路径设置在哪里以及如何设置它们?

I'm a bit confused about how paths work with gems. Here's the core of my confusion:

>> require 'rubygems' => false >> Gem.available?('money') => true >> require 'money' LoadError: no such file to load -- money from (irb):3:in `require' from (irb):3 from /usr/bin/irb:12:in `<main>' >> Gem.available?('pony') => false >> require 'pony' => true

This is being run by irb 0.9.5(05/04/13) This is especially confusing because gem list --local yields:

*** LOCAL GEMS *** albino (1.0) bcat (0.5.2) builder (2.1.2) bundler (1.0.0) classifier (1.3.3) diff-lcs (1.1.2) directory_watcher (1.3.2) fast-stemmer (1.0.0) gdata (1.1.1) gdata2 (0.1) github-markup (0.5.0) gollum (1.0.1) google4r-checkout (1.0.6.1) grit (2.2.0) jekyll (0.7.0) kwalify (0.7.1) liquid (2.2.2) maruku (0.6.0) mime-types (1.16) mocha (0.9.8) money (3.0.5) mustache (0.11.2) nokogiri (1.4.3.1) rack (1.2.1, 1.1.0) rake (0.8.7) rubygems-update (1.3.7) sanitize (1.2.1) sinatra (1.0) syntax (1.0.0) unicorn (1.1.3)

which notably contains money but not pony.

Here's the outputs of gem env:

RubyGems Environment: - RUBYGEMS VERSION: 1.3.7 - RUBY VERSION: 1.9.1 (2010-01-10 patchlevel 378) [x86_64-linux] - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.9.1 - RUBY EXECUTABLE: /usr/bin/ruby1.9.1 - EXECUTABLE DIRECTORY: /usr/bin - RUBYGEMS PLATFORMS: - ruby - x86_64-linux - GEM PATHS: - /usr/lib/ruby/gems/1.9.1 - /home/aresnick/.gem/ruby/1.9.1 - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :benchmark => false - :backtrace => false - :bulk_threshold => 1000 - REMOTE SOURCES: - http://rubygems.org/

And in case that doesn't make it clear, gem and ruby are using the same ruby, i.e.:

aresnick@dror:~$ which ruby /usr/bin/ruby aresnick@dror:~$ ls -al $(which ruby) lrwxrwxrwx 1 root root 22 2010-08-28 20:08 /usr/bin/ruby -> /etc/alternatives/ruby aresnick@dror:~$ ls -al /etc/alternatives/ruby lrwxrwxrwx 1 root root 18 2010-08-28 20:08 /etc/alternatives/ruby -> /usr/bin/ruby1

I suspect the problem is with the paths that are being looked at, especially because of the other gems which I can and can't access, e.g. gdata is not available and sinatra is. . .

aresnick@dror:~$ gem which pony /var/lib/gems/1.9.1/gems/pony-1.0/lib/pony.rb aresnick@dror:~$ gem which money /usr/lib/ruby/gems/1.9.1/gems/money-3.0.5/lib/money.rb aresnick@dror:~$ gem which sinatra /var/lib/gems/1.9.1/gems/sinatra-1.0/lib/sinatra.rb aresnick@dror:~$ gem which gdata /usr/lib/ruby/gems/1.9.1/gems/gdata-1.1.1/lib/gdata.rb aresnick@dror:~$ irb >> require 'sinatra' => true >> require 'gdata' LoadError: no such file to load -- gdata from (irb):2:in `require' from (irb):2 from /usr/bin/irb:12:in `<main>'

So, I think that the /usr/lib/ruby/gems/1.9.1 gems are not being found and the /var ones are. I'm sure mucking around with symlinks could fix this, but I was wondering a) why this was happening and b) where are these paths are set and how can I set them?

最满意答案

我在Debian系统上遇到了类似的问题,我猜你正在使用它或者基于系统,因为你正在使用替代品,问题是我通过apt-get安装了rubygems然后安装通过源代码更新的版本。

把事情弄好了。

Debian和rubygems团队之间存在某种“宗教”战争,因此在Debian上安装rubygems更容易。

我没有解释发生了什么。 :(

I've had similar problems on a Debian system, which I'm guessing you're using or a system based off of since you're using alternatives, and the problem then was that I had installed rubygems through apt-get and then installed an updated version through source.

Messed things up good.

There is some kind of "religious" war between the Debian and rubygems team so it's just easier to installed rubygems from source on Debian.

I've no explanation for what is happening though. :(

更多推荐

本文发布于:2023-07-26 03:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1270705.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么区别   Gem   require   difference   gems

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!