# How do I know what to require in my ruby script?

**URL:** <https://www.ruby-forum.com/t/how-do-i-know-what-to-require-in-my-ruby-script/179939>\
**Category:** Ruby\
**Created:** [December 8, 2009, 1:14pm UTC](https://www.ruby-forum.com/t/how-do-i-know-what-to-require-in-my-ruby-script/179939 "2009-12-08T13:14:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 8, 2009, 1:14pm UTC](https://www.ruby-forum.com/t/how-do-i-know-what-to-require-in-my-ruby-script/179939/1 "2009-12-08T13:14:21Z")

</div>

Hello all,

How do I know what ‘require’ to include after installing a ruby gem?  
The reason I ask is because I just installed the pdf-writer gem, but  
none of these work:

require ‘pdf-writer’  
require ‘pdf’  
require ‘pdfwriter’

After installing a ruby gem, how do I know what string to put in my  
require statement? thanks for any info.

---

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 8, 2009, 1:22pm UTC](https://www.ruby-forum.com/t/how-do-i-know-what-to-require-in-my-ruby-script/179939/2 "2009-12-08T13:22:10Z")

</div>

On Dec 8, 2009, at 8:44 AM, Omar C. wrote:

> After installing a ruby gem, how do I know what string to put in my  
> require statement? thanks for any info.

Read the documentation. While it is good practice that you just have  
to require a file with the same name of the gem, this is not enforced.  
In the case of pdf::writer, it is:

require ‘pdf/writer’

This follows another popular convention, where modules are folders and  
nested classes are files. All this can be found in the Pdf::Writer  
manual, to be found at:

[http://ruby-pdf.rubyforge.org/pdf-writer/manual/index.html](http://ruby-pdf.rubyforge.org/pdf-writer/manual/index.html)

Regards,  
Florian G.

---

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 8, 2009, 1:25pm UTC](https://www.ruby-forum.com/t/how-do-i-know-what-to-require-in-my-ruby-script/179939/3 "2009-12-08T13:25:40Z")

</div>

On Tuesday 08 December 2009, Omar C. wrote:

> | After installing a ruby gem, how do I know what string to put in my  
> |require statement? thanks for any info.  
> |

Usually, such information is included in the documentation of the gem.  
It can  
be either in the API documentation which rubygems automatically creates  
when  
you install the gem or on the gem website. In the case of pdf-writer,  
the  
project’s home page, which you can access from rubyforge, includes a  
manual  
([http://ruby-pdf.rubyforge.org/pdf-writer/manual/manual.pdf](http://ruby-pdf.rubyforge.org/pdf-writer/manual/manual.pdf)). At the  
beginning  
of chapter 2, there’s a simple example, which begins with the line

require ‘pdf/writer’

I hope this helps

Stefano

---

<div class="post-metadata">

**Author:** ![tutiplain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/77aa72/32.png) [@tutiplain](https://www.ruby-forum.com/u/tutiplain)\
**Post date:** [December 8, 2009, 1:36pm UTC](https://www.ruby-forum.com/t/how-do-i-know-what-to-require-in-my-ruby-script/179939/4 "2009-12-08T13:36:00Z")

</div>

Stefano C. wrote:

> On Tuesday 08 December 2009, Omar C. wrote:
> 
> > | After installing a ruby gem, how do I know what string to put in my  
> > |require statement? thanks for any info.  
> > |
> 
> Usually, such information is included in the documentation of the gem.  
> It can  
> be either in the API documentation which rubygems automatically creates  
> when  
> you install the gem or on the gem website. In the case of pdf-writer,  
> the  
> project’s home page, which you can access from rubyforge, includes a  
> manual  
> ([http://ruby-pdf.rubyforge.org/pdf-writer/manual/manual.pdf](http://ruby-pdf.rubyforge.org/pdf-writer/manual/manual.pdf)). At the  
> beginning  
> of chapter 2, there’s a simple example, which begins with the line
> 
> require ‘pdf/writer’
> 
> I hope this helps
> 
> Stefano

Thanks, this was just what I was looking for. Borrowing from this  
example, it seems that the require string is the path of the gems .rb  
file, starting from the /lib/ folder inside the Ruby installation. In  
the case of the pdf-writer gem, it is /lib/pdf/witer, so the require is  
pdf/writer/, just like you said. And you’re right, it does appear in  
the docs 🙂
