I am trying to create a method to calculate the shipping cost for a package. The shipping cost comes in a table which states the weight range and the corresponding price.
Example data:
0 - 50g : $1
51 - 100g : $2
How should I structure my data, how can I generate the price dynamically based on the data instead of writing many if
statements?
Example code:
def price_for_weight(w)
if w < 50
return 1
elsif w < 100
return 2
end