Gems not working

V

Vincent Predoehl

I do not have rails, but I like to use Ruby Gems. I installed gem
hpricot and when I run my script with 'ruby', it has trouble finding the
Hpricot library. When I run the same code in IRB, it finds the gem. I
do have require 'rubygems' before require 'hpricot'. The code fails on
line 5, where I use the hpricot library for the first time ( which seems
strange )

require 'rubygems'
require 'pricot'
require 'open-uri'
# load the RedHanded home page
doc = Hpricot(open("http://redhanded.hobix.com/index.html"))
# change the CSS class on links
(doc/"span.entryPermalink").set("class", "newLinks")
# remove the sidebar
(doc/"#sidebar").remove
# print the altered HTML
puts doc


This situation occurs when I run the script from teh command line:

ruby hpricot.rb

The same code runs perfectly in IRB. It would seem that IRB knows more
about gems while the ruby interpretor does not. What can I do about
this? Thanks.
 
A

Alex Young

Vincent said:
I do not have rails, but I like to use Ruby Gems. I installed gem
hpricot and when I run my script with 'ruby', it has trouble finding the
Hpricot library. When I run the same code in IRB, it finds the gem. I
do have require 'rubygems' before require 'hpricot'. The code fails on
line 5, where I use the hpricot library for the first time ( which seems
strange )

require 'rubygems'
require 'pricot'
-----------^ typo?
 
V

Vincent Predoehl

Alex said:
-----------^ typo?

I saw the typo and fixed it. I regret the typo because it only added to
the confusion, but I still have the same problem.
 
A

Alex Young

Vincent said:
I saw the typo and fixed it. I regret the typo because it only added to
the confusion, but I still have the same problem.
What platform is this on? What's the exact error?
 
R

Ryan Davis

require 'rubygems'
require 'pricot'
...

This situation occurs when I run the script from teh command line:

ruby hpricot.rb

name the script different from the thing you are requiring... 'test-
hpricot.rb' maybe.
 
V

Vincent Predoehl

It's b/c you call your file 'hpricot.rb', rename the file to something
else and it should work.

The platform is MacOS X Tiger. I installed hpricot using balloons from
here and it works:
http://balloon.hobix.com/hpricot

The file name was probably the problem though. Either way I got it
working and I renamed the file.
 

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

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,201
Latest member
KourtneyBe

Latest Threads

Top