Each of the “when” conditions is a range object. The “else” condition
is obviously not. Range objects can be a key in a hash, so you can
have (untested)
{ 0…100 => 1, 101…500 => 2, …, :else => 0 }
and that Hash can be stored as YAML.
Then you need to write a method
def level_for_xp(hash, xp)
…
end
which is easily done.
Rather than a hash, I would go for an array of arrays:
[ [0…100, 1], [101…500, 2], …, [:else, 0] ]
Reason: preserve order. I know the current implementation of Ruby’s
hashes does preserve insertion order, but that’s an implementation
detail. For this usage, preserving order is a conceptual detail.