这是 Ruby 1.8 问题:
我们都知道如何使用Array#uniq
:
[1,2,3,1].uniq #=> [1,2,3]
但是我想知道我们是否可以通过猴子修补它来处理复杂的对象。当前的行为是这样的:
[{"three"=>"3"}, {"three"=>"4"}, {"three"=>"3"}].uniq
#=> [{"three"=>"3"}, {"three"=>"4"}, {"three"=>"3"}]
请求的是:
[{"three"=>"3"}, {"three"=>"4"}, {"three"=>"3"}].uniq
#=> [{"three"=>"3"}, {"three"=>"4"}]