[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

PDF::Writer and rubygems

Bill Woodward

5/14/2008 5:48:00 PM

Good morning,

I am trying to use the pdf-writer ruby gem via NetBeans, but I'm having
trouble doing it. If I run the 'hello.rb' demo program without updating
it to use rubygems, I get the following error:

/home/wpwood/Desktop/pdf_writer-1.1.8/demo/hello.rb:16:in `require': no
such file to load -- pdf/writer (LoadError)
from /home/wpwood/Desktop/pdf_writer-1.1.8/demo/hello.rb:16

I then update it to use rubygems by changing the 'require' section of
the code to:

require 'rubygems'
gem 'pdf-writer'

but when I do that, I get an error:

/home/wpwood/Desktop/pdf_writer-1.1.8/demo/hello.rb:14: uninitialized
constant PDF (NameError)

on the line:

pdf = PDF::Writer.new

I'm fairly new to Ruby, and new to trying to use gems directly, and it's
certainly possible that I'm doing something wrong. So, can anyone tell
me what I'm doing wrong?

Thanks,
- Bill
--
Posted via http://www.ruby-....

3 Answers

Lyle Johnson

5/14/2008 6:25:00 PM

0

On Wed, May 14, 2008 at 12:47 PM, Bill Woodward <wpwood@gmail.com> wrote:

> I then update it to use rubygems by changing the 'require' section of
> the code to:
>
> require 'rubygems'
> gem 'pdf-writer'
>
> but when I do that, I get an error:
>
> /home/wpwood/Desktop/pdf_writer-1.1.8/demo/hello.rb:14: uninitialized
> constant PDF (NameError)
>
> on the line:
>
> pdf = PDF::Writer.new
>
> I'm fairly new to Ruby, and new to trying to use gems directly, and it's
> certainly possible that I'm doing something wrong. So, can anyone tell
> me what I'm doing wrong?

You were close. You need to say:

require 'rubygems'

to load the RubyGems runtime support, then:

gem 'pdf-writer'

to activate that gem, and finally,

require 'pdf/writer'

to require that specific module (for the PDF::Writer class definition).

Hope this helps,

Lyle

Bill Woodward

5/14/2008 6:31:00 PM

0

Lyle Johnson wrote:
>
> You were close. You need to say:
>
> require 'rubygems'
>
> to load the RubyGems runtime support, then:
>
> gem 'pdf-writer'
>
> to activate that gem, and finally,
>
> require 'pdf/writer'
>
> to require that specific module (for the PDF::Writer class definition).
>
> Hope this helps,
>
> Lyle

Gotcha, thanks. I was under the impression that 'gem' would also
'require' the module. Is that the difference between this and the old
'require_gem'?

- Bill
--
Posted via http://www.ruby-....

Lyle Johnson

5/14/2008 9:03:00 PM

0

On Wed, May 14, 2008 at 1:30 PM, Bill Woodward <wpwood@gmail.com> wrote:

> Gotcha, thanks. I was under the impression that 'gem' would also
> 'require' the module. Is that the difference between this and the old
> 'require_gem'?

Yes. The 'gem' method just adds the gem's files to Ruby's LOAD_PATH,
but it doesn't actually 'require' (load) any code into the
interpreter.