[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Should "new" methods do anything?

Austin Ziegler

9/12/2003 10:28:00 PM

On Sat, 13 Sep 2003 05:03:51 +0900, Philip Mak wrote:
> For example, let's say I have a class called "Httpd" which runs an HTTP
> server. Should its interface be like this:
> server = Httpd.new(:listen_port => 80) # Initialize the server
> server.run # Run it
> Or like this?
> Httpd.new(:listen_port => 80) # Initialize and run the server
> The latter way is more streamlined, but feels bad for some reason that I
> can't quite put into words right now.

I would say:

server = Httpd.new(:listen_port => 80)
server.run

or

Httpd.new(:listen_port => 80) do |server|
...
end

If there's a block given, then both run it and stop it when the block
completes.

-austin
--
austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.09.12
* 18.25.22