开发者

Can not find gems running "ruby <my_script>.rb" – but works in IRB

I am experiencing issues when I am trying to run my .rb-file with the Ruby-command trying to access a gem. The gem i am trying to use is Ruby-Whois. I have an example script below that when I try to execute it through "ruby whois.rb" I get this error message:

./whois.rb:6: uninitialized constant Whois (NameError)

However, if I run the same script line by line in IRB I get the expected result. What may cause this?

开发者_如何学JAVA

Below is whois.rb

require "rubygems"
require "whois"

domain = "google.com"

c = Whois::Client.new
a = c.query(domain)

puts a


change the name of your file - there is ambiguity in require 'whois' and ruby is requireing your file instead of a gem. when you do it line by line in irb ruby knows what you exactly want to require, so everything works.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜