From: michael libby Date: 2002-08-11T09:06:48+09:00 Subject: Re: extend Html4? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Saturday 10 August 2002 18:44, Philip Mak wrote: > How can I become able to write it like this? > > > puts p{"Hello, "+b{"world"}+"!"} > > I want the "p", "b" etc. methods to be exported to my namespace. They > are defined inside Html4: Here's what I did, although it may not suit your tastes: class MyCGI < CGI def hello_world return p{"Hello, " + b{"world"} + "!"} end end c = MyCGI.new("html4") puts c.hello_world This way I can keep all the messages in my subclass, where they are fairly self-contained. This way, if I ever need to switch from CGI to XML or plain output for the screen, instead of rewriting my main module, I just have to make a MyXML or MyMessages class and use it in my main script instead. I also build methods to translate CGI stuff like parameters into what my main script needs to know. Prevents my main script from having to know that the request started life as CGI. Not that I ever expect to do need to switch from CGI to something else, but the main benefit is that it keeps program logic separate from message output logic, so both the program and output code is easier to follow... and it makes writing the HTML methods a lot easier. -michael ++++++++++++++++++++++++++++++++++++++++++ Michael C. Libby public key: http://www.ichimunki.com/public_key.txt web site: http://www.ichimunki.com ++++++++++++++++++++++++++++++++++++++++++ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE9Vagi4ClW9KMwqnMRAtcaAJ91F5nyrnpOYD5OkrcPU/HHn2FKygCdGou1 jXOJ7kuQ6o0RfCe9E51UXsk= =VGm2 -----END PGP SIGNATURE-----