Time and again, developers fail to compare gem or ruby version numbers correctly. It’s an easy mistake to make.
There’s a great post that comes up on top of Google that recommends using
This works correctly, including for pre-release versions.
However, especially in this last case it may not be what you want. In fact, it’s almost never what you want. Consider the following example with
RUBY_VERSION = 2.6.6.pre1.
This doesn’t work because “2.6.6.pre1” is not newer than “2.6.6”.
The desired effect can be achieved easily.
Another common pattern that I have observed is to check versions at runtime.
Avoid evaluating this
if multiple times by declaring different methods depending on the Ruby version.
We can also hide this implementation detail in some cases using the with-version gem. Consider contributing to support more if-then-else scenarios.