maetthew
maetthew

Reputation: 311

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?

Below is whois.rb

require "rubygems"
require "whois"

domain = "google.com"

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

puts a

Upvotes: 0

Views: 317

Answers (1)

jmatraszek
jmatraszek

Reputation: 808

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.

Upvotes: 5

Related Questions