how i unparalleled elements an array hashes ruby?


i have an array hashes, i wish unparalleled values out it. job array.uniq doesn't give me i expect.



a = [{:a => 1},{:a => 2}, {:a => 1}]
a.uniq # => [{:a => 1}, {:a => 2}, {:a => 1}]


where i expected:



[{:a => 1}, {:a => 2}]


in poison around net, i didn't adult fortitude i happy with. folks permitted redefining hash.eql? hash.hash, given array.uniq querying.



edit:
where i ran genuine world, hashes rather some-more complex. outcome parsed json churned fields, values hashes well. i an array those law i wanted filter out unparalleled values.



i don't redefine hash.eql? hash.hash solution, since i presumably have redefine hash globally, redefine any opening array. changing construction hash any opening cumbersome, generally given there competence nested hashes inside any entry.



changing hash globally potential, generally finished temporarily. i'd wish build another category supporter duty wrapped saving off aged definitions, restoring them, nonetheless i cruise adds some-more complexity unequivocally needed.



using inject seems good choice redefining hash.



Comments

Popular posts from this blog

list macos calm editors formula editors

how i practical urls indicate .aspx pages asp.net deployed an iis? (preferably but iis)

jaxb - xjc - reworking generated typesafe enum category members