-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi!
Ruby's sorting these strings by ASCII order, and as you can see here, capital letters come first! So "A" is always less than 'a', etc.
This is because Ruby follow the lexicographical order for sorting. If you need
case-insensitive comparisons, you can change the way the sorting works with:
puts '1sqHmb5b8G9mN' < '1Xv5LeB9bMdar'
puts 'a' < 'B'
class String
alias <=> casecmp
end
puts '1sqHmb5b8G9mN' < '1Xv5LeB9bMdar'
puts 'a' < 'B'
Let's see what ri tell us about casecmp:
ri casecmp
- --------------------------------------------------------- String#casecmp
str.casecmp(other_str) => -1, 0, +1
- ------------------------------------------------------------------------
Case-insensitive version of String#<=>.
"abcdef".casecmp("abcde") #=> 1
"aBcDeF".casecmp("abcdef") #=> 0
"abcdef".casecmp("abcdefg") #=> -1
"abcdef".casecmp("ABCDEF") #=> 0
Best regards,
- --
Eustáquio "TaQ" Rangel
http://eustaquiorangel.com
"When someone says, 'I want a programming language in which I need only say what
I want done,' give him a lollipop."
Alan Perlis
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
iD8DBQFHIzTYb6UiZnhJiLsRApzlAKCPKoMhI2Wt+puNwOJQB3yo2gTBHQCfd2Pf
R/rIWKh9b7/tXJphk7KRziI=
=wNTo
-----END PGP SIGNATURE-----