How to use a string (stored in a variable) to find a symbol in a hash. Ruby : I have a question that seems fairly basic, and I searched the site and did not see it asked (so I hope this is not a duplicate).

The simple problem I am trying to solve is that I have some user input that will be a string.  I need to use this string to see if there is a key/symbol that exists in the hash, like this:


    # user gives input about what category that they want to retrieve, and it is stored in a variable called category: 
    category = "cupcake"
    
    products = {
        :cupcakes => [{:title => "chocolate", :flavor => "chocolate"}, {:title => "summer special", :flavor => "pink cake"}],
        :cookies => [{:title => "chocolate bliss", :flavor => "chocolate chip"}, {:title => "breakfast surprise", :flavor => "oatmeal raisin"}]
    }
    
    # This one does not work because category is a string, not a symbol
    p products.key?(category)
    # This one does not work because :cupcake is a unique symbol, and we are just creating another symbol
    p products.key?(category.to_sym)

