2016-11-08 70 views
0

我的标题可能不能准确反映我想要问的内容,但这是我能够真正实现的最好方法。导入并使用红宝石

我想要做的是对库进行修改,并在项目中测试这些修改。所以我运行了RVM,一个名为project/的项目文件夹,一个2.3.1的gemset,以及库git克隆到文件夹project/metasm/中。我有一个具有此行中有一个文件project/Gemfile

gem "metasm", :path => "metasm" 

当我运行bundle install我得到如下:

Using metasm 1.0.2 from source at `metasm` 
Using bundler 1.13.6 
Bundle complete! 1 Gemfile dependency, 2 gems now installed. 
Use `bundle show [gemname]` to see where a bundled gem is installed. 

好,所以一切似乎工作,因为它应该。真棒。我下降到irb和去require图书馆/宝石,但它似乎并不太适合我。

2.3.1 :001 > require "metasm" 
LoadError: cannot load such file -- metasm 
    from /home/chiggins/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' 
    from /home/chiggins/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' 
    from (irb):1 
    from /home/chiggins/.rvm/rubies/ruby-2.3.1/bin/irb:11:in `<main>' 

现在,这里是我不是很了解。为什么我不能使用metasm,即使bundle install按照它应该的方式工作?

这是我认为这将工作的最佳方式。理想情况下,我希望能够根据自己的需要对metasm库进行更改,并运行irb或Ruby脚本来测试/验证我的更改。这是一个很好的方法去解决这个问题,或者我应该以另一种方式去解决问题吗?

感谢您的帮助!

+0

你用'bundle exec irb'输入irb吗? –

+0

这听起来像是你的ruby安装在你的gem目录中有一个metasm的副本,并且它的源代码在你的问题中有一个副本。如果你的项目文件夹中有gem的源代码,那么你并没有真正将它用作“宝石”。是否删除Gemfile声明并调用'require'metasm/metasm''工作? – Kache

+0

@LucasCosta - 如果我这样做并运行'require'metasm“'它会返回'false'。 @Kache - 从Gemfile中删除条目,运行'bundle install',删除到'irb',并运行'require“metasm/metasm”'返回相同的文件。 – Chiggins

回答

1

您必须使用bundle exec irb命令输入irb。

如您所见,herebundle exec <command>执行该命令使Gemfile中指定的所有gem在Ruby程序中都可用。

+0

为我工作!谢谢卢卡斯! – Chiggins