1

whois使用$ gem install whois并遵循Ruby Whois
进行安装, 但是当我在 irb 中对其进行测试时,它给出了错误:

1.9.3p194 :001 > c = Whois::Client.new
NameError: uninitialized constant Whois
from (irb):1
from /home/darshana/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
from /home/darshana/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
from /home/darshana/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>

编辑

当我require 'whois'给出另一个错误时:

1.9.3p194 :003 > require 'whois'
LoadError: cannot load such file -- whois
from /home/darshana/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
from /home/darshana/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require'
from /home/darshana/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
from /home/darshana/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
from (irb):3
from /home/darshana/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
from /home/darshana/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
from /home/darshana/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

谢谢。

4

3 回答 3

2

尝试安装并加载对我有用的 whois 库。

> gem install whois
> irb
* require 'whois'  
* c = Whois::Client.new
>>  #<Whois::Client:0x8f0fa34 @timeout=10, @settings={}>
于 2012-09-04T10:05:03.660 回答
1

有时默认情况下不需要gem,因为这个时候我们需要这个gem。

例如(在您的情况下),您在 Gemfile 中添加了 whois gem,然后打开控制台给出以下行

require "whois"

然后应该可以使用 Whois 常量。

于 2012-09-04T10:06:22.590 回答
0

如果这是在您的 gemfile 中,则加载 irbbundle exec rails c

于 2012-09-04T10:32:36.590 回答