Join GitHub today
String does not use <=> to compare two string instances #2396
From: http://jira.codehaus.org/browse/JRUBY-3925. Differs from MRI on JRuby 1.7.18 and JRuby 9000.
There seems to be different behavior between JRuby 1.3.1 and MRI Ruby 1.8.7p72 when it comes to String comparison. MRI uses the <=> operator, whereas JRuby does not. This became an issue when I was trying to write a class that acted as an Enum type (for use with rails backed by postgres). The class was a subclass of String that overrode <=> to perform the comparison using an internal array containing the Enum values rather than the value of the Strings themselves. I was a bit surprised when my tests passed under ruby, but failed under jruby.
I've included a small test program and the output of both JRuby 1.3.1 and Ruby 1.8.7p72 (unfortunately, it isn't a junit test case, my apologies)