January 2009
4 posts
1 tag
Using the Ruby Array#uniq with custom classes
You may (or may not) have noticed that when you create a custom class in Ruby, Array#uniq — and friends — no longer work as advertised. You can override the eql?, equal?, ==, and still not get it right.
For the solution, you must override both the eql? and hash member methods of your custom object:
class MyFoo
attr_reader :custom_unique_id
# Internally, Ruby converts your...
1 tag
1 tag
Fox News, Fear Imbalance. God, I hate Fox News. Smite them, please.
1 tag