# Problem seeing classes in rubygem

**URL:** <https://www.ruby-forum.com/t/problem-seeing-classes-in-rubygem/86113>\
**Category:** Ruby\
**Created:** [March 23, 2006, 5:51pm UTC](https://www.ruby-forum.com/t/problem-seeing-classes-in-rubygem/86113 "2006-03-23T17:51:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 23, 2006, 5:51pm UTC](https://www.ruby-forum.com/t/problem-seeing-classes-in-rubygem/86113/1 "2006-03-23T17:51:12Z")

</div>

Ruby 1.8.2

I am trying to take advantage of a Rubygem named RubyfulSoup (a port of  
the PHP BeautifulSoup module).

I have installed the gem correctly (it shows up when I do gem -list) and  
my require\_gem statement succeeds.

However, when I go to instantiate one of the classes defined in this  
gem, the call fails with:

unitialized constant: BeautifulSoup

on line 4 of my test case below.

Here is my test case:

require ‘rubygems’  
require\_gem ‘rubyful\_soup’, ‘\>= 1.0.4’

parser = BeautifulSoup.new(%{“kajsdlfkjads”})

Does anyone understand why the class name inside of the rubyful\_soup.rb  
file cannot be seen successfully?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 23, 2006, 6:35pm UTC](https://www.ruby-forum.com/t/problem-seeing-classes-in-rubygem/86113/2 "2006-03-23T18:35:55Z")

</div>

On Fri, 2006-03-24 at 01:51 +0900, Wes G. wrote:

> Here is my test case:
> 
> require ‘rubygems’  
> require\_gem ‘rubyful\_soup’, ‘\>= 1.0.4’
> 
> parser = BeautifulSoup.new(%{“kajsdlfkjads”})

require\_gem does (by default) actually require anything inside the gem -  
it’s just used to tell Gems about version constraints you want to have.  
You’ll still have to require ‘rubyful\_soup’ to actually load it.

note 1: In normal use, Gems patches require to automatically load gems  
as needed, so you could have just had “require ‘rubyful\_soup’” and the  
latest installed version would be installed. If you really do need that  
version constraint, however, I think you have to keep the require\_gem.

note 2: Gems does support an ‘autorequire’ attribute in a gem’s spec  
that allows it to automatically require a given file when the Gem itself  
is required, but this is deprecated and rubyful soup doesn’t appear to  
use it.

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 23, 2006, 6:41pm UTC](https://www.ruby-forum.com/t/problem-seeing-classes-in-rubygem/86113/3 "2006-03-23T18:41:32Z")

</div>

On Mar 23, 2006, at 5:51 PM, Wes G. wrote:

> Ruby 1.8.2
> 
> I am trying to take advantage of a Rubygem named RubyfulSoup (a  
> port of  
> the PHP BeautifulSoup module).

Python actually.

> require ‘rubygems’  
> require\_gem ‘rubyful\_soup’, ‘\>= 1.0.4’

Unless you _really need_ version 1.0.4, you can drop this and just do  
require ‘rubyful\_soup’.

– Daniel

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 23, 2006, 6:52pm UTC](https://www.ruby-forum.com/t/problem-seeing-classes-in-rubygem/86113/4 "2006-03-23T18:52:22Z")

</div>

On 3/23/06, Ross B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Here is my test case:
> > 
> > require ‘rubygems’  
> > require\_gem ‘rubyful\_soup’, ‘\>= 1.0.4’
> > 
> > parser = BeautifulSoup.new(%{“kajsdlfkjads”})
> 
> require\_gem does (by default) actually require anything inside the gem -

I assume you meant “doesn’t” above. A caveat is what you mention below  
regarding autorequire.

> is required, but this is deprecated and rubyful soup doesn’t appear to  
> use it.

Based on what you’ve said it seems that

1. There is no point in using require\_gem unless you want to specify  
version constraints instead of just using the newest version of the  
gem.
2. Since autorequire is being deprecated, you should never just use  
require\_gem. You should also use a require to pull in a specific file  
within the gem.

Does anyone disagree with these recommendations?

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 23, 2006, 7:47pm UTC](https://www.ruby-forum.com/t/problem-seeing-classes-in-rubygem/86113/5 "2006-03-23T19:47:56Z")

</div>

On Fri, 2006-03-24 at 02:52 +0900, Mark V. wrote:

> > > on line 4 of my test case below.  
> > > I assume you meant “doesn’t” above.

Oops, yes, typo there.

> Based on what you’ve said it seems that
> 
> 1. There is no point in using require\_gem unless you want to specify  
> version constraints instead of just using the newest version of the  
> gem.
> 2. Since autorequire is being deprecated, you should never just use  
> require\_gem. You should also use a require to pull in a specific file  
> within the gem.

Yes, in fact I think that’s what the Gems team now recommend.
