Unique array of hashes by key value

OK, so… I have an array of hashes like this:

[
    { :id => 0, :text => "someText" },
    { :id => 1, :text => "anotherText" },
    { :id => 2, :text => "someText" }
]

What I want, is to “filter” hashes with duplicate :text values, so that the result is:

[
    { :id => 0, :text => "someText" },
    { :id => 1, :text => "anotherText" },
]

How can I do that?


P.S. Of course, I can find a way and do it. What I’m asking for is the best (& fastest) Ruby-friendly way, given that I’m not such a Ruby guru. 😉


Source: ruby

Leave a Reply