On Tue, Mar 1, 2011 at 4:45 PM, John [email protected] wrote:

Since the doc explicitly defines Hash as the underlying store, and

since Hash in 1.9.2 observes insertion order (http://ruby-doc.org/core/

classes/Hash.html) during enumeration, I wonder if the doc for Set

should be changed?

I was hoping someone who had a detailed knowledge of Set and Hash

would give you an answer. Since I don’t qualify on the detailed

knowledge grounds, I’ll try my knowledge of logic, and hope that fits.

Set implements a collection of unordered values with no duplicates,

which means that you shouldn’t assume the elements will be in a

particular order (alphabetical, time of insertion into the set,etc) if

you iterate over the set using each: that’s important.

But if the current implementation happens to use another class (Hash)

which does have an order (time of insertion), then that’s not

important. Code *might* use the fact that using Set with its current

use of Hash means that the iteration order is time of first insertion

into the set (ignoring complications of inserting, then deleting, then

reinserting an element).

But given the actual documentation of Set, it would be unwise to do

this: a later implementation of Set might use something other than an

insertion order preserving Hash.

In short, I think the documentation for Set should remain as it is. Or

possibly say explicitly that whilst the current implementation of Set

uses Hash for storage, it should not be assumed that this will always

be the case.