How do I get the unique elements from an array of hashes in Ruby?

后端 未结 8 946
抹茶落季
抹茶落季 2020-12-28 14:57

I have an array of hashes, and I want the unique values out of it. Calling Array.uniq doesn\'t give me what I expect.

a = [{:a => 1},{:a =&g         


        
相关标签:
8条回答
  • 2020-12-28 15:36

    found on google http://mikeburnscoder.wordpress.com/2008/01/18/uniquify-an-array-of-hashes-in-ruby/

    0 讨论(0)
  • 2020-12-28 15:41

    The answer you give is similar to the one discussed here. It overrides the hash and eql? methods on the hashes that are to appear in the array which then makes uniq behave correctly.

    0 讨论(0)
提交回复
热议问题