`

rubygems.org guides 翻译十四(faq)

    博客分类:
  • gem
faq 
阅读更多

这些年来,rubygems开发团队已经收到了许多反馈,以下是一份用户过去和现在频繁提出的反馈意见。

 

我们也在 RubyGems Support 站点和IRC in #rubygems回答疑问。 你可以找到如下:

I installed gems with --user-install and their commands are not available —————————————————————————

When you use the --user-install option, RubyGems will install the gems to a directory inside your home directory, something like ~/.gem/ruby/1.9.1. The commands provided by the gems you installed will end up in ~/.gem/ruby/1.9.1/bin. For the programs installed there to be available for you, you need to add ~/.gem/ruby/1.9.1/bin to your PATH environment variable.

For example, if you use bash you can add that directory to your PATH by adding code like this to your ~/.bashrcfile:

if which ruby >/dev/null && which gem >/dev/null; then
    PATH="$(ruby -rubygems -e 'puts Gem.user_dir')/bin:$PATH"
fi

After adding this code to your ~/.bashrc, you need to restart your shell for the changes to take effect. You can do this by opening a new terminal window or by running exec $SHELL in the window you already have open.

How can I trust Gem code that’s automatically downloaded? ———————————————————

The same way you can trust any other code you install from the net: ultimately, you can’t. You are responsible for knowing the source of the gems that you are using. In a setting where security is critical, you should only use known-good gems, and possibly perform your own security audit on the gem code.

The Ruby community is discussing ways to make gem code more secure in the future, using some public-key infrastructure. To see the progress of this discussion, visit the rubygems-trust organization on GitHub.

Why does require 'some-gem' fail? ———————————–

Not every library has a strict mapping between the name of the gem and the name of the file you need to require. First you should check to see if the files match correctly:

$ gem list RedCloth

*** LOCAL GEMS ***

RedCloth (4.1.1)
$ ruby -rubygems -e 'require "RedCloth"'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- RedCloth (LoadError)
  from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
  from -e:1
$ gem contents --no-prefix RedCloth | grep lib
lib/case_sensitive_require/RedCloth.rb
lib/redcloth/erb_extension.rb
lib/redcloth/formatters/base.rb
lib/redcloth/formatters/html.rb
lib/redcloth/formatters/latex.rb
lib/redcloth/formatters/latex_entities.yml
lib/redcloth/textile_doc.rb
lib/redcloth/version.rb
lib/redcloth.rb
$ ruby -rubygems -e 'require "redcloth"'
$ # success!

If you’re requiring the correct file, maybe gem is using a different ruby than ruby:

$ which ruby
/usr/local/bin/ruby
$ gem env | grep 'RUBY EXECUTABLE'
   - RUBY EXECUTABLE: /usr/local/bin/ruby1.9

In this instance we’ve got two ruby installations so that gem uses a different version than ruby. You can probably fix this by adjusting a symlink:

$ ls -l /usr/local/bin/ruby*
lrwxr-xr-x  1 root  wheel       76 Jan 20  2010 /usr/local/bin/ruby@ -> /usr/local/bin/ruby1.8
-rwxr-xr-x  1 root  wheel  1213160 Jul 15 16:36 /usr/local/bin/ruby1.8*
-rwxr-xr-x  1 root  wheel  2698624 Jul  6 19:30 /usr/local/bin/ruby1.9*
$ ls -l /usr/local/bin/gem*
lrwxr-xr-x  1 root  wheel   76 Jan 20  2010 /usr/local/bin/gem@ -> /usr/local/bin/gem1.9
-rwxr-xr-x  1 root  wheel  550 Jul 15 16:36 /usr/local/bin/gem1.8*
-rwxr-xr-x  1 root  wheel  550 Jul  6 19:30 /usr/local/bin/gem1.9*

You may also need to give irb the same treatment.

Why does require return false when loading a file from a gem? ————————————————————-

Require returns false when loading a file from a gem. Usually require will return true when it has loaded correctly. What’s wrong?

Nothing’s wrong. Well, something. But nothing you need to worry about.

A false return from the require method does not indicate an error. It just means that the file has already been loaded.

RubyGems has a feature that allows a file to be automatically loaded when a gem is activated (i.e. selected). When you require a file that is in an inactive gem, the RubyGems software will activate that gem for you. During that activation, any autoloaded files will be loaded for you.

So, by the time your require statement actually does the work of loading the file, it has already been autoloaded via the gem activation, and therefore the statement returns false.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

    gemstash, 一个 RubyGems.org 缓存和 private gem 服务器.zip

    gemstash, 一个 RubyGems.org 缓存和 private gem 服务器 什么是 Gemstash?Gemstash是远程服务器( 如 https://rubygems.org ) 和 private gem 源的缓存。在你的控制范围内,如果你使用的是多个可以访问服务器的...

    rubygems-update-3.1.3.gem

    A package (also known as a library) contains a set of functionality that can be invoked by a Ruby program, such as reading and parsing an XML ... See our guide on publishing a Gem at guides.rubygems.org

    meg:帮助管理和支持 RubyGems.org 的快速命令

    帮助管理和支持 RubyGems.org 的快速命令。 目前帮助通过 SSH 连接到 RubyGems.org 基础设施和运行命令。 安装 $ cd $ git clone git://github.com/rubygems/meg.git .meg 对于 bash 用户: $ echo 'eval "$($...

    Ruby Toolbox data on Rubygems.org-crx插件

    在Rubygems.org上查看Ruby Toolbox数据 此Chrome扩展程序从Ruby工具箱(https://www.ruby-toolbox.com/)中提取信息,以显示在rubygems.org上。 例如,如果您正在https://rubygems.org/gems/simplecov上查看诸如...

    adoption.rubygems.org

    option.rubygems.org 项目导师的姓名: Nick Quaranto,Benjamin Fleischer 项目团队的名称:丽娜·托雷斯(Lina Torres)的安吉拉(Angela Guette) 项目名称: RubyGems.org采用中心 网址: : 关于该项目: ...

    rubygems.org:Ruby社区的gem托管服务

    RubyGems.org(néeGemcutter) Ruby社区的gem主机。 目的 提供更好的API处理宝石 创建更透明,更易于访问的项目页面 使社区能够改善和增强网站 支持 由管理, 是一个社区资助的组织,通过门票和赞助为和的会议...

    rubygems.org-backup:这是历史重写之前 ruby​​gems.org 的 BACKUP 存储库。 不使用。 请不要拉请求

    RubyGems.org(姓氏 Gemcutter) Ruby 社区的 Gem 托管。目的提供更好的 API 来处理 gems 创建更透明和可访问的项目页面使社区能够改进和增强站点链接 :#rubygems 在 Freenode 上: : :贡献请遵循我们的。 要进行...

    2.4-3.0.rubygems.rar

    gem包管理

    rubygems-incident-verifiers

    ##概括此处提供的工具使您能够将 gem 的本地副本与 Rubygems.org 上的副本进行检查。 这些工具旨在让 gem 开发人员根据 Rubygems.org 服务器检查他们的本地开发副本(为什么?请参阅文档末尾的注释)。 目前正在...

    rubygems-1.8.7.gz for linux

    rubygems-1.8.7.gz rubygems-1.8.7.gz

    曲柄的Rubygems「Crank for Rubygems」-crx插件

    ★导航至ruby gem的GitHub或Rubygems.org页面。 在GitHub上打开'Gemfile'或'.gemspec'文件,然后单击任何gem名称。 您将被重定向到gem项目页面。 ★从上下文菜单中打开RubyGems.org中的ruby gem页面。 用鼠标突出...

    rubygems-master-(1).zip_GEM

    Download from: rubygems.org/pages/download Unpack into a directory and cd there Install with: ruby setup.rb # you may need admin/root privilege For more details and other options, see: ruby setup....

    RubyGems.txt

    RubyGems

    guides:努力为RubyGems生态系统提供出色的文档

    从rubygems.org/pages/docs移植内容 从help.rubygems.org知识库移植内容 在这里找到许多StackOverflow / ruby​​-talk问题并获得其常见答案 填写更多指南! 设置 确保已gem install jekyll ( gem install jekyll ...

    gemstash:RubyGems.org缓存和私有gem服务器

    今天或什至更好的做出贡献,并确保Bundler,RubyGems,Gemstash和其他共享工具在未来数年内都存在。 快速入门指南 设置 Gemstash旨在快速,轻松地进行设置。 到本《快速入门指南》结束时,您将能够将公共资源中的...

    rubygems-3.2.12.tgz

    rubygems-3.2.12.tgz

    rubygems-2.7.4.tgz

    rubygems-2.7.4.tgz centos6.5安装redmine时需要的软件包

    Crank for Rubygems-crx插件

    ★导航到ruby gem的github或rubygems.org页面。 在github上打开'gemfile'或'.gemspec'文件,然后单击任何宝石名称。 您将被重定向到GEM项目页面。 ★从上下文菜单中打开RubyGems.org中的Ruby Gem页面。 在使用鼠标的...

Global site tag (gtag.js) - Google Analytics