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

O

Omar Campos

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.
 
F

Florian Gilcher

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.

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

Regards,
Florian Gilcher
 
S

Stefano Crocco

|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.
|

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). At the beginning
of chapter 2, there's a simple example, which begins with the line

require 'pdf/writer'

I hope this helps

Stefano
 
O

Omar Campos

Stefano said:
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). 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 :)
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top