How to remove duplicates in a hash in Ruby on Rails?

后端 未结 4 1655
眼角桃花
眼角桃花 2020-12-15 23:39

I have a hash like so:

[
  {
    :lname => \"Brown\",
    :email => \"james@intuit.com\",
    :fname => \"James\"
  },
  {
    :lname => nil,
            


        
4条回答
  •  一个人的身影
    2020-12-16 00:27

    In Ruby 1.9.2, Array#uniq will accept a block paramater which it will use when comparing your objects:

    arrays.uniq { |h| h[:email] }
    

提交回复
热议问题