I’m having some troubles trying to understand how cover? method for Range class works.
From the docs it is said:
cover?(val) → true or false : Returns true if obj is between beg and end, i.e beg <= obj <= end (or end exclusive when exclude_end? is true).
When I do this:
test = "A".."X"
I expect test.cover? "AX" to fail because the object AX to me it seems to be outside that range limits. However it returns true. Then I do: test.cover? "XX" and it returns false
I don’t see how AX is in that range and in general I believe it is being difficult to see how cover? works for objects that are not Numeric. So my question is: How is that the object “AX” is in that range, but the object “XX” is not.
Taking a shot in the dark here, but I’m assuming it is because “AX” comes after “A” so it within the range, while “XX” comes after “X” which would be outside the range.
Checking in IRB you can see: