# (no subject)

**URL:** <https://www.ruby-forum.com/t/no-subject/74954>\
**Category:** Ruby\
**Created:** [November 7, 2006, 11:04am UTC](https://www.ruby-forum.com/t/no-subject/74954 "2006-11-07T11:04:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Parragh\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@Parragh\_S](https://www.ruby-forum.com/u/Parragh_S)\
**Post date:** [November 7, 2006, 11:04am UTC](https://www.ruby-forum.com/t/no-subject/74954/1 "2006-11-07T11:04:02Z")

</div>

Hello,  
sorry for the repost, but still have no solution, but really would like  
to find it:) So could someone please help me a bit – can I not extend  
classes with new methods in mod\_ruby?

–

I’m trying some code with mod\_ruby where I make a postgresql connection.  
The following works fine:

require ‘postgres’

def with\_db  
db = PGconn.connect(‘localhost’, 5432, ‘’, ‘’, ‘template1’,  
‘postgres’, ‘’)  
begin  
yield db  
ensure  
db.close  
end  
end

with\_db do |db|  
row = db.query(‘SELECT VERSION()’)  
puts row  
end

But when I alter the code extending the PGconn class to do the result  
set ceanup like this:

require ‘postgres’

class PGconn  
alias :exec\_no\_block :exec  
def exec(sql)  
res = exec\_no\_block(sql)  
return res unless block\_given?  
begin  
yield res  
ensure  
res.clear if res  
end  
end  
end

def with\_db  
db = PGconn.connect(‘localhost’, 5432, ‘’, ‘’, ‘template1’,  
‘postgres’, ‘’)  
begin  
yield db  
ensure  
db.close  
end  
end

with\_db do |db|  
db.exec(‘SELECT VERSION()’) do |res|  
puts res[0]  
end  
end

The latter code works from command line, making the same output as the  
first one, however, with mode\_ruby I get the following error in apache  
error.log:

[Sat Nov 04 13:28:08 2006] [error] mod\_ruby: error in ruby  
[Sat Nov 04 13:28:08 2006] [error] mod\_ruby: /var/www/ruby/e1b.rb:20:in  
`with_db': undefined method`connect’ for #Module:0xb6fb45b4::PGconn  
(NoMethodError)

Could someone please help me out with this? It might be an obvious fault  
in my code, but I cannot figure it out.

Thanks:  
Szab

–  
Parragh S.  
web: parszab.nir.hu

---

<div class="post-metadata">

**Author:** ![Parragh\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@Parragh\_S](https://www.ruby-forum.com/u/Parragh_S)\
**Post date:** [November 7, 2006, 11:04am UTC](https://www.ruby-forum.com/t/no-subject/74954/2 "2006-11-07T11:04:41Z")

</div>

Parragh S. wrote:

> Hello,  
> sorry for the repost, but still have no solution, but really would  
> like to find it:) So could someone please help me a bit – can I not  
> extend classes with new methods in mod\_ruby?
> 
> –
> 
> I’m trying some code with mod\_ruby where I make a postgresql  
> connection. The following works fine:

\> fault in my code, but I cannot figure it out. \> \> Thanks: \> Szab

Try restarting Apache. If you modify a library mod\_ruby has already  
loaded, it won’t be reloaded until Apache is restarted.

-Justin
