【问题标题】:whois doesn't work in irbwhois 在 irb 中不起作用
【发布时间】:2012-09-04 09:57:18
【问题描述】:

我使用$ gem install whois 安装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>'

谢谢。

【问题讨论】:

  • 你应该首先要求 'whois'
  • @railscard :我这样做了,但它给出了错误LoadError: cannot load such file -- whois
  • 你能用“gem search whois”找到whois gem吗?
  • 将 gem 'whois' 添加到您的项目 gemfile 中,然后重试

标签: ruby-on-rails ruby irb whois whois-ruby


【解决方案1】:

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

> gem install whois
> irb
* require 'whois'  
* c = Whois::Client.new
>>  #<Whois::Client:0x8f0fa34 @timeout=10, @settings={}>

【讨论】:

  • 我这样做并给了我错误LoadError: cannot load such file -- whois
  • 你安装了whois gem吗?
  • 是的。 darshana@darshana-pc:~/rails_projects/whois_test$ gem search whois *** LOCAL GEMS *** whois (2.6.4)
  • 我认为您使用的是 rails 控制台而不是 irb 控制台。尝试在您的 gemfile ( gem 'whois' ) 运行包中添加 whois gem,然后运行 ​​rails 控制台并再次执行 require 'whois'
【解决方案2】:

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

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

require "whois"

那么使用 Whois 常量应该是可用的。

【讨论】:

  • 我这样做并给了我错误LoadError: cannot load such file -- whois
  • 我认为你安装的 gem 没有包含在你的目录路径中,只要进入 gem 里面找到 whois.rb 文件。然后打开 irb give require "./whois"。
【解决方案3】:

如果这是在您的 gemfile 中,则使用 bundle exec rails c 加载 irb

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-05
    • 1970-01-01
    • 1970-01-01
    • 2013-07-06
    • 1970-01-01
    • 1970-01-01
    • 2014-05-07
    相关资源
    最近更新 更多