开发者

Ruby gem File path

So I'm sort of a dummy here, I'm using examples from inside a gem, the AMQP gem for ruby here on github, I've pulled the repo and in one of the example files (this one) it has a few lines like this:

$LOAD_PATH.unshift File.expand_path("../../../../lib", __FILE__)

require "amqp"

# [...]

The load path points to this directory. So my question is mainly this, when I have the gem installed and I try to run a file using just ruby or even in IRB It won't work outside the gems examples directory when referencing those lib files... why? even when I require "amqp"?

Any ideas would be greatly appreciated.


Update I'm wondering if there are two gems or libraries that are conflicting, for example, that library links to:

https://github.com/ruby-amqp/amqp

I'm just so confused because I don't know if this is the same as the gem "amqp", how can I tell, the .gemspec and Gemfile isn't clear to me, and it seems to have other things like:

开发者_C百科custom_gem "amq-client",   :git => "git://github.com/ruby-amqp/amq-client.git",   :branch => "master"
custom_gem "amq-protocol", :git => "git://github.com/ruby-amqp/amq-protocol.git", :branch => "master"

And in the .gemspec is has:

s.add_dependency "amq-client"

Any help, helping me understand this would be so awesome!


Presumably, it has that line included so you can run the example file directly from the source tree without having the gem installed.

If you have the gem installed, and you have RubyGems loaded, then you should be able to just say require "amqp" and it will be appropriately required.

Note that you need to have RubyGems loaded in order for require "amqp" to load the AMQP gem; you need to either do a require "rubygems" at the beginning of your source file, or start Ruby with -rubygems, or set the RUBYOPT environment variable export RUBYOPT=rubygems. See the RubyGems manual for more information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜