Re: Global method usage in standard libs
- From: Joel VanderWerf <joelvanderwerf@xxxxxxxxx>
- Date: Wed, 7 Jul 2010 12:11:56 -0500
Alexander E. Fischer wrote:
Pathname['/home/someone']
I like this pattern. Note that there is some precedent in the core:
Array, Hash, and Struct classes all have a [] class method (not
necessarily equivalent to #new).
It's also fairly well used in the stdlib and the gems I happen to have
installed:
$ ri '[]' | grep -oP '\S+::\[\]\S+'
WEBrick::HTTPStatus::[],
Dir::[],
Array::[],
Hash::[],
Set::[],
Matrix::[],
Vector::[],
Generators::AllReferences::[],
Net::SSH::Version::[],
YAML::Pairs::[],
YAML::Omap::[],
Webby::Filters::[],
Webby::Filters::[],
CodeRay::FileType::[],
Pure::[],
Rake::Task::[],
Rake::FileList::[],
JSON::[],
JSON::[],
MIME::Types::[],
OrderedHash::[],
NArray::[],
Nokogiri::EncodingHandler::[],
Nokogiri::HTML::ElementDescription::[],
Nokogiri::CSS::Parser::[]=,
Nokogiri::CSS::Parser::[],
MultiRBTree::[],
But note that some of these, like Dir#[], are not the same as #new.
But I don't know how easy it will be to convince people to live with the
deprecation warning for Pathname et al. I wouldn't mind it.
.
- References:
- Global method usage in standard libs
- From: Alexander E. Fischer
- Global method usage in standard libs
- Prev by Date: Re: Ruby switches
- Next by Date: Re: Ruby switches
- Previous by thread: Global method usage in standard libs
- Next by thread: New, but this seems odd...
- Index(es):
Relevant Pages
|