From: Kirk Haines Date: 2010-06-19T03:01:29+09:00 Subject: Re: String comparison. Why does Ruby consider this true? On Fri, Jun 18, 2010 at 11:46 AM, Abder-rahman Ali wrote: > When I try for example to compare the following strings in Ruby, I get > "true". > > puts 'Xeo' < 'ball' > > When I make 'Xeo' start with a lowercase letter, i get 'false' > > puts 'xeo' < 'ball' > > The second statement is clear, but why when I capitalize 'Xeo' I get > true? Uppercase letters come before lowercase letters. You can look at the implementation in the source (start at rb_str_cmp()), but if you dig deeply enough, it comes down to the way the standard C library function memcmp() works. It compares bytes. And an ASCII 'X' is represented by a smaller value (88) than an ASCII 'b' (98). So 'Xeo' is less than 'ball'. Kirk Haines Developer Engine Yard