[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

customize a gem method

Abir B.

5/29/2008 8:43:00 AM

Hello,
I want to customize a method of a gem wuthout changing the source code
of this gem .
Is that possible?
Thanks
--
Posted via http://www.ruby-....

1 Answer

Sean O'Halpin

5/29/2008 8:46:00 PM

0

On Thu, May 29, 2008 at 9:42 AM, Abir B. <abboura84@yahoo.fr> wrote:
> Hello,
> I want to customize a method of a gem wuthout changing the source code
> of this gem .
> Is that possible?

Sure is:

require 'rubygems'
require 'pdf/writer'

w = PDF::Writer.new
w.text_width("Hello World") # => 51.67

class PDF::Writer
def text_width(s)
42.0
end
end
w.text_width("Hello World") # => 42.0

Regards,
Sean