On 7 February 2013 17:52, alexeymuranov (Alexey Muranov) < redmine@ruby-lang.org> wrote:
=begin
In my opinion, (({Hash#keys})) should return an instance of (({Set})).
=end
Is this related to an earlier request to create OrderedHash as an alias of
Hash? If that were to happen, I'd be happy if OrderedHash#keys returned an
Array, and Hash#keys returned a Set. However if Hash remains explicitly
ordered, Hash#keys should be likewise explicitly ordered (i.e. an Array).
Unless we're also adding to spec that Set is insertion-ordered.
Matthew, in some sense it is indeed related to #5123, because both are about Set and Hash abstractions. However, it is independent, because as long as Hash is ordered, so is Set. If ever #5123 is accepted and OrderedHash is separated from Hash, there will be also OrderedSet in addition to Set.
Martin, i will think about your request, but i do not really think in "use cases". I just think that "keys" of a Hash behave as a Set and not as an Array.
The first problem for me is that Hash is part of core while Set is part of the standard lib. One cannot have core depend on lib.
The second problem is that hash#keys has returned an array for the entire history of Ruby. It is far from clear to me that breaking that assumption is a good idea.
Now, Hash#key_set, defined when you do require 'set', has possibilities, if you have a use case.