1

I have a tiny, plain (i.e. non-Rails) Ruby project that I'm trying to get to work with the addressable gem. Here's what happens:

$ ruby -r rubygems sign.rb
sign.rb:5:in `require': cannot load such file -- addressable (LoadError)
    from sign.rb:5:in `<main>'

This is the Gemfile:

source "http://rubygems.org"

gem "addressable", "~> 2.3.2"

This is sign.rb:

#!/usr/bin/env ruby

require "rubygems"
require "bundler/setup"
require "addressable"

That's all there is to it. Why doesn't it want to use the gem?

4

2 回答 2

2

没有addressable您可以要求的文件,只有addressable目录。您需要在所需的目录下要求特定文件,例如:

require 'addressable/uri'
uri = Addressable::URI.parse("http://example.com/path/to/resource/")
# etc ...

或者

require "addressable/template"
template = Addressable::Template.new("http://example.com/{?query*}/")
# etc...

查看addressable文档

于 2013-07-29T16:14:49.710 回答
0

您之前是否使用 安装了 gem $ bundle install

这将获取您的 Gemfile 中指定的 gem,并使其可用于工作目录。

于 2013-07-29T16:06:13.287 回答