require_gem scoping issue?

  • Thread starter Pawel Szymczykowski
  • Start date
P

Pawel Szymczykowski

Hi all,

I'm running into a weird problem with rubygems and using
'require_gem'. Given the following code,

-- being code --

require 'rubygems'
require_gem 'mechanize', '>= 0.6.3'

class MyClass

def initialize
@agent = WWW::Mechanize.new # Line 7
end

end

mc = MyClass.new # Line 12

-- end code --

I get this error:

NameError: uninitialized constant MyClass::WWW

method initialize in untitled document at line 7
at top level in untitled document at line 12

Could it be that I'm missing something really obvious? When I replace
the require_gem line with just "require 'mechanize'", it works
according to my expectations. I'm using ruby 1.8.4, rubygems 0.9.0
(also tried with 0.8.11) and mechanize is at 0.6.3 as a gem. It
doesn't seem to matter if the explicit version is there or not, the
same error is produced.

Thanks!

-Pawel
 
P

Pawel Szymczykowski

Hi all,

I'm running into a weird problem with rubygems and using
'require_gem'. Given the following code,

Hm.. nevermind. I'm a fool. A foolish fool. I just found the following
pages that explains the issue:

http://redhanded.hobix.com/inspect/autorequireIsBasicallyGoneEveryone.html
http://desperatepundit.com/blog/cre...30/Ruby-Tip-1-require-gem-is-unnecessary.html

So it looks like I have to do:

require_gem 'mechanize', '>= 0.6.3'
require 'mechanize'

In order to require and load a specific version of a gem. Oh well.

-Pawel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top