When compare two version strings, to_f does not work well:
> "1.5.8".to_f > "1.5.7".to_f
=> false
string comparison is better, but not always correct:
> "1.5.8" > "1.5.7"
=> true
> "1.5.8" > "1.5.9"
=> false
> "1.5.8" > "1.5.10" # oops!
=> true
How to compare version strings properly?
An idea: create a
Object#compare_bymethod that behaves likecompare(aka the spaceship operator Object#<=>) but takes a custom block:You can also take a more specific approach still based on the
comparemethod: