Hi I'm using RoR, and I'm stumped by this problem, I'm looking for the simplest way to extract from a hash, members that have unique values. For example:

Code Ruby:
//key is ID, value is option name
options = {18=>"Size", 19=>"Size", 20=>"Color"}
--> options = {18=>"Size", 20=>"Color"}

This problem stems from having a products model, with a join model to product options, e.g. Size, Color. When a product is added to the shopping cart, a LineItem model is created and I need to add default options to the line_item, but since fetching product.option gives me a hash of all of it's options like {18=>"Size", 19=>"Size", 20=>"Color"} I don't want to add duplicate option types.

Here's what my code in the line items controller looks like right now (this controller is responsible for adding items to the cart):
Code Ruby:
@product = Product.find(params[:product_id])
@line_item = LineItem.new(
    :cart => current_cart, 
    :product => @product, 
    :quantity => defined?(params[:line_item][:quantity]) ? params[:line_item][:quantity] : 1, 
    :unit_price => @product.price
@line_item.product_options = @product.product_options
->[#<ProductOption id: 18, product_id: 8, option: "Size", value: "Medium", line_item_id: 47>, 
   #<ProductOption id: 19, product_id: 8, option: "Size", value: "Large", line_item_id: 45>,  
   #<ProductOption id: 20, product_id: 8, option: "Color", value: "Black", line_item_id: 45>]

I need a line item to have only one Size option and one Color option.

The reason this problem exists is because the Products have a product_options association, and those options consist of a database record for each possible option a product can have. But the Line Item is the actual product in a user's cart and it can only have 1 of each type of option.

So I need to get a line item's associated product's options, but only those of a unique type. Size, Color, etc.

Any ideas?