Ruby invert hash
Hi all, This is how to invert hash manually. path_names = {:glass=>"gelas", :metals=>"", :other=>"lainnya", :papers=>"kertas", :plastics=>"plastik"} new_names = path_names.inject({}) { |h, (k, v)| h[v] = k; h } The result: {"gelas"=>:glass, "lainnya"=>:other, "kertas"=>:papers, "plastik"=>:plastics}