I am trying to get all the keys with the same value from a hash and put them into an array as separate entries. I have this line of code but it sends everything in as a sing
I suggest you construct a hash rather than an array.
h = { a: 1, b: 2, c: 1, d: 3, e: 2 } h.each_with_object({}) { |(k,v),g| (g[v] ||= []) << k } #=> {1=>[:a, :c], 2=>[:b, :e], 3=>[:d]}
This answers the question posed by the title of the question.