From: "David A. Black" Date: 2004-04-05T00:18:48+09:00 Subject: Re: good module use? Hi -- On Sun, 4 Apr 2004, Lionel Thiry wrote: > Bauduin Raphael a �crit : > > > 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 > To use a module variable through "MyModule.my_var", just prefix the > variable name in the module with "self." or "@@". Not exactly; @@var is a class variable; self.var is a method call. If you want an association between them, you have to write appropriate methods: class X def self.my_var @@my_var end # etc. end David -- David A. Black dblack@wobblini.net