From: David Vallner Date: 2006-12-04T03:26:03+09:00 Subject: Re: Intermittant problem with Hpricot --------------enig2EF5DBE831F7F191B8208007 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Allison Newman wrote: > I've run into a wierd problem with the Hpricot gem. I don't know if > this is a problem with gems in general on my system, or if it's specifi= c > to Hpricot, so I'm posting here. >=20 > Basically I have code as follows: > require 'rubygems' > require 'net/http' > require 'uri' > require_gem 'hpricot' >=20 > class Page > def some_function(html_text) > doc =3D Hpricot(html_text) > doc.search("/html/body//img").each do |img| > logger.debug("=3D=3D Found an image: #{img} =3D=3D") > src =3D img[/src=3D"/] > logger.debug("src =3D #{src}") > end > end > end >=20 >=20 > When the function is called, sometimes I get a message saying that > function Hpricot does not exist for the object of type Page. this > continues for the entire programming session. >=20 > But sometimes, when I sit down to work on the project, the code works! > It continues working until I restart the Rails server (this is a Rails > project running on MacOSX). >=20 > Does anyone have any idea what might be causing this problem, and how t= o > correct it? >=20 > Alli >=20 This might or might not be related, but I think there was some change to the semantics of require_gem lately (appeared in a post or thread a week or two ago?), or HPricot might have been changed not to load any files when the gem is loaded. Either way, (I think) you should just use #require, not #require_gem and directly require files inside the Hpricot gem - Rubygems is intended to be as transparent to use as possible, and at least personally I prefer code agnostic to how a certain library might be packaged on the given system. Try using require 'hpricot' instead or require_gem 'hpricot' and see if that helps? Also, Rails has a hard dependency on rubygems, so you don't need to require those in Rails code. David Vallner --------------enig2EF5DBE831F7F191B8208007 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (MingW32) iD8DBQFFcxa3y6MhrS8astoRAhCzAJ4hqzVwtBHsyVCnvYgBeRWSaBojGQCdEsWZ vXWgc6SeKMPhSkrZWBbhJh0= =oekr -----END PGP SIGNATURE----- --------------enig2EF5DBE831F7F191B8208007--