Re: Global method usage in standard libs



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.

.



Relevant Pages

  • Duck Typed Concepts for Ruby (was Re: A use case for an ordered hash)
    ... An Sequencable mixin can be defined that implements all sorts of operations such as append, concat, splice, sort, etc. ... extending an instance of Array with Sorted if the array is known to be sorted. ... Now returning to the thread at hand we can see that the difference between the associative array and hash hierarchies is that the hash hierarchy depends upon Hashable keys. ...
    (comp.lang.ruby)
  • Re: Suggestions for double-hashing scheme
    ... >> The items that are being moved are the items in the hash table itself, ... >> which are of fixed size (they are in an array, ... > typedef struct { ... One "uchar" aka 'unsigned char' is plenty to hold a probe ...
    (comp.programming)
  • [SUMMARY] Index and Query (#54)
    ... This was a fun quiz for me because I really don't know anything about indexing ... We see in initializethat the index is just a Hash. ... an Array of symbolic document names where the word can be found ). ...
    (comp.lang.ruby)
  • Re: Comment on how to uniquely track your objects in C# / hash table / get hash code
    ... Array, correct? ... This is largely irrelevant to the issue of performance, since hash ... where both insertions and lookups happen frequently, ... about fast lookups for balanced red/black binary trees. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: combining hashes
    ... >>> A hash is an ordered data structure indexed by a specific key. ... My mind's eye sees it differently. ... c> An array is ...
    (comp.lang.perl.misc)