Howdie,
I helped a guy out on IRC a couple of days ago and it set me to asking a
question. He wanted to uniquify an array, but the natural equality of
his objects was not how he wanted to do it. So, this screams out the
need for a block, but uniq doesn't accept one. I gave him this solution
instead:
~ h = {}
~ a.each { |x| h[x.thing] = x unless h.include?(x.thing) }
~ uniques = h.values
Total overkill when the following would be more fun:
~ a.uniq! { |x, y| x.thing == y.thing }
or something similar...
It seems strange that this hasn't already been done. There must be a
good reason...
Thoughts?
Regs,
Derek