From: Kenichi Kamiya Date: 2012-02-21T03:11:30+09:00 Subject: Re: array.uniq on specific attributes # an approach class Array   private     def _uniq_by(&block)     new, memo = [], {}       map(&block).each_with_index do |mapped, idx|       unless memo[mapped]         memo[mapped] = true         new << self[idx]       end     end         new   end     alias_method :_uniq, :uniq   alias_method :_uniq!, :uniq!     public     def uniq(&block)     block_given? ? _uniq_by(&block) : _uniq   end     def uniq!(&block)     if block_given?       new = _uniq_by(&block)         if self == new         nil       else         replace(new)       end     else       _uniq!     end   end end # 1.9.2 original http://ideone.com/Uygbz # same return from 1.8.6, 1.8.7, 1.9.2, 1.9.3 http://ideone.com/ySoIE -- Posted via http://www.ruby-forum.com/.