Skip to content

Instantly share code, notes, and snippets.

@kronos
Created October 7, 2010 10:33
Show Gist options
  • Save kronos/614937 to your computer and use it in GitHub Desktop.
Save kronos/614937 to your computer and use it in GitHub Desktop.
From cdd86270d9696184bd13182635d14a29a4455618 Mon Sep 17 00:00:00 2001
From: Ivan Samsonov <[email protected]>
Date: Thu, 7 Oct 2010 14:31:36 +0400
Subject: [PATCH] Fix String#casecmp. Fixes #518
---
kernel/common/string.rb | 11 +++++------
1 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/kernel/common/string.rb b/kernel/common/string.rb
index 4e175a7..515998b 100644
--- a/kernel/common/string.rb
+++ b/kernel/common/string.rb
@@ -424,6 +424,7 @@ class String
size = order < 0 ? @num_bytes : to.num_bytes
i = 0
+ space = ?\s
while i < size
a = @data[i]
b = to.data[i]
@@ -432,18 +433,16 @@ class String
r = a - b
next if r == 0
- if (a.islower or a.isupper) and (b.islower or b.isupper)
- r += r < 0 ? ?\s : -?\s
+ if (a.islower and b.isupper) or (b.islower and a.isupper)
+ r += r < 0 ? space : -space
end
next if r == 0
- return -1 if r < 0
- return 1
+ return r < 0 ? -1 : 1
end
return 0 if order == 0
- return -1 if order < 0
- return 1
+ return order < 0 ? -1 : 1
end
# If <i>integer</i> is greater than the length of <i>self</i>, returns a new
--
1.6.6.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment