Ok, firstly, you just save the lines from SomeSet#add , you need to save an Element instance, for example:
def add(o) @elements.add(Element.new(o)) self end
And you need to implement the hash method in your Element class.
You can convert Element#@element to lowercase and pass its hash.
def hash element.downcase.hash end
Full code and demo: http://codepad.org/PffThml2
Edit: for my input comment O (n) above:
The inserts are O (1). From what i see, eql? used only with hash of 2 elements. Since we execute hash in a smaller version of the element, it will be pretty well distributed, but eql? should not be called much (if it is called at all).
Dogbert
source share