B
Bauduin Raphael
Hi,
I thought to create a module to add an instance variable representing
the connection to a database:
module MyDbModule
attr :conn
require "postgres"
pghost="localhost"
pgport=nil
pgoptions=nil
pgtty=nil
dbname="mydb"
user='mylogin'
password='mypassword'
@conn=PGconn.connect(pghost,pgport,pgoptions,pgtty,dbname,user,password)
end
However, this doesn't work. The Pickaxe describes modules as a group of
calsses, methods, constants, which my modules doens't respect (no method
defined).
Is there a way to achieve what I'm trying, and in the case that it would
be possible, is it a good approach?
An alternative would be to put all code in a method and call this method
to initialise @conn. I'm wondering if I can get rid of the call to this
method though.
Thanks.
Raph
I thought to create a module to add an instance variable representing
the connection to a database:
module MyDbModule
attr :conn
require "postgres"
pghost="localhost"
pgport=nil
pgoptions=nil
pgtty=nil
dbname="mydb"
user='mylogin'
password='mypassword'
@conn=PGconn.connect(pghost,pgport,pgoptions,pgtty,dbname,user,password)
end
However, this doesn't work. The Pickaxe describes modules as a group of
calsses, methods, constants, which my modules doens't respect (no method
defined).
Is there a way to achieve what I'm trying, and in the case that it would
be possible, is it a good approach?
An alternative would be to put all code in a method and call this method
to initialise @conn. I'm wondering if I can get rid of the call to this
method though.
Thanks.
Raph