D
David Garamond
When writing short scripts (several pages long) I often want to share
some variables (like CGI object, DB connection object) in several
methods. I often use globals for this:
$cgi = CGI.new('html3')
$conn = PGconn.connect(...)
def foo
$conn.exec(...)
$cgi.out { ... }
end
When I don't want to see all those dollar signs, I use a wrapper method:
$_cgi = CGI.new('html3')
def cgi; $_cgi end
def foo
cgi.out { ... }
end
But it still looks ugly to me. Any suggestion to make it more elegant?
some variables (like CGI object, DB connection object) in several
methods. I often use globals for this:
$cgi = CGI.new('html3')
$conn = PGconn.connect(...)
def foo
$conn.exec(...)
$cgi.out { ... }
end
When I don't want to see all those dollar signs, I use a wrapper method:
$_cgi = CGI.new('html3')
def cgi; $_cgi end
def foo
cgi.out { ... }
end
But it still looks ugly to me. Any suggestion to make it more elegant?