From: Ben Giddings Date: 2004-07-03T00:29:59+09:00 Subject: Re: ruby-dev summary 23763-23840 Minero Aoki wrote: > [ruby-dev:23784] URI() > > TANAKA Akira proposed a new global method URI(), to construct an URI > object. With this method, you can write HTTP GET program as below: > > print URI("http://www.example.com/").read > > This program is better than `open("http://....").read' because it > properly closes IO objects. > > Here are some opinions: (+ : approval, - : objection) > > + There are similar methods such as Integer(), String(), etc. > + URI is a name, literal-like syntax seems good. > - URI.[] is better because URI() pollutes the global name space. > - String(obj) calls obj.to_s. Integer(obj) calls obj.to_i. > But URI(obj) does not call obj.to_uri. > (Note that Complex(obj) does not call obj.to_complex, too.) > - A method name which begins with a capital looks bad. I like the idea of a simple way to deal with URIs, but I agree with all the objections this idea. Is there some reason it couldn't be a factory method of a URI class, making the example like: URI.create("http://www.example.com").read The factory method, 'create' could return URI type objects, customized for that particular URI. For a local file: irb> URI.create("file:///path/to/local/file.txt") => # For a HTTP connection it would return a HTTP object, for gopher a Gopher object, etc. Sure, it's an extra 6 keystrokes (one for the dot, 5 for create) but it seems to satisfy the objections. Maybe someone has a better option for the factory method name? Ben