简体   繁体   中英

whois doesn't work in irb

I install whois using $ gem install whois and follow Ruby Whois
but when I test it in irb, it gives error:

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>

EDIT

when I require 'whois' gives another error:

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>'

Thanks.

Try to install and load the whois library .. that worked for me.

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

Sometimes gems cant be required by default, for this time we need to require this gem.

For example(in your case), you added whois gem in Gemfile, then open console give following line

require "whois"

then use Whois constant should be available.

如果这是在你的gemfile中,而不是使用bundle exec rails c加载irb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM