Suppose I have a FruitDetector class which takes in a string and returns the possible types of fruit with different probabilities as a hash:
type = {
banana: 0.2,
lemon: 0.4,
orange: 0.4
}
What would be the cleanest, most idiomatic way to select one random element from the N maximal values in the hash (in this case, to randomly select between lemon and orange), returning the name of the fruit?
The cleanest way is to do it step by step: