Caleb Codes

Delete Non-unique Hash Values in Ruby

1
2
3
4
h = {:cat => "cat", :dog => "dog", :fish => "dog"}
arr = Array.new
h.each{|key, val| arr.include?(val) ? h.delete(key) : arr « val }
=> {:cat=>"cat", :dog=>"dog"}

Comments