我安装了一个gem,但需要'gemname'不起作用。为什么? [英] I have a gem installed but require 'gemname' does not work. Why?

查看:82
本文介绍了我安装了一个gem,但需要'gemname'不起作用。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真正问的问题是为什么require不采用宝石的名字。另外,如果没有,那么最简单的方法是找到秘密咒语来要求该死的东西!?

举例来说,如果我有 memcache-client 然后我必须要求它使用

  require'rubygems' 
require'memcache'


解决方案

你需要包含什么文件的标准是。但是有一些常见的约定,您可以按照以下方法尝试和使用:


  • 通常文件被称为相同的
    称为宝石。所以 require mygem
    将会起作用。

  • 通常文件是
    ,它是宝石的lib
    子目录中唯一的.rb文件,因此如果
    可以获得宝石的名称(也许
    通过2.1 rails
    项目中的
    vendor / gems进行读取),那么您可以检查
    #{gemname} / lib 为.rb文件,

    ,如果只有一个,那么需要一个相当美元的b $ b



如果所有这些都有效,那么您只需查看gem的目录(通过运行 gem environment | grep INSTALLATION | awk'{print $ 4}'并查看lib目录,您可能需要阅读这些文件,并希望有解释该做什么的注释。


The question I'm really asking is why require does not take the name of the gem. Also, In the case that it doesn't, what's the easiest way to find the secret incantation to require the damn thing!?

As an example if I have memcache-client installed then I have to require it using

require 'rubygems'
require 'memcache'

解决方案

There is no standard for what the file you need to include is. However there are some commonly followed conventions that you can can follow try and make use of:

  • Often the file is called the same name as the gem. So require mygem will work.
  • Often the file is the only .rb file in the lib subdirectory of the gem, So if you can get the name of the gem (maybe you are itterating through vendor/gems in a pre 2.1 rails project), then you can inspect #{gemname}/lib for .rb files, and if there is only one, its a pretty good bet that is the one to require

If all of that works, then all you can do is look into the gem's directory (which you can find by running gem environment | grep INSTALLATION | awk '{print $4}' and looking in the lib directory, You will probably need to read the files and hope there is a comment explaining what to do

这篇关于我安装了一个gem,但需要'gemname'不起作用。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆