summaryrefslogtreecommitdiff
path: root/lib/rdoc/code_object/method_attr.rb
diff options
context:
space:
mode:
authorMike Dalessio <[email protected]>2024-11-30 11:06:51 -0500
committergit <[email protected]>2024-11-30 16:06:54 +0000
commit83bd9191d8537e0c5c413841a2234552d2a3b756 (patch)
treec1a4fb3d6a88a0726f6f4df281edacf13c5b5fac /lib/rdoc/code_object/method_attr.rb
parentc321cf0e95c08854c02514eb2e2729da83c1dcc4 (diff)
[ruby/rdoc] Methods are sorted symbols-first
(https://github.com/ruby/rdoc/pull/1219) There are three distinct ranges of symbols in ASCII: - the range below "A", 0..64 in decimal - the range between "Z" and "a", 91..96 in decimal - the range above "z", 123..127 in decimal With this change, any method starting with a character in these "symbol ranges" will be sorted before a method starting with an alpha ASCII character. The remaining methods, all starting with alpha or 8-bit characters, will be sorted against each other exactly as before. Specifically this addresses the issue from #1204 which is that `#[]` and `#^` were previously sorted _after_ the alpha methods. These methods will now be sorted before alpha methods. Fixes https://github.com/ruby/rdoc/pull/1204 https://github.com/ruby/rdoc/commit/a4f13d242b
Diffstat (limited to 'lib/rdoc/code_object/method_attr.rb')
-rw-r--r--lib/rdoc/code_object/method_attr.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/rdoc/code_object/method_attr.rb b/lib/rdoc/code_object/method_attr.rb
index 27e6599bc1..d7fefa55d4 100644
--- a/lib/rdoc/code_object/method_attr.rb
+++ b/lib/rdoc/code_object/method_attr.rb
@@ -114,8 +114,8 @@ class RDoc::MethodAttr < RDoc::CodeObject
return unless other.respond_to?(:singleton) &&
other.respond_to?(:name)
- [ @singleton ? 0 : 1, name] <=>
- [other.singleton ? 0 : 1, other.name]
+ [@singleton ? 0 : 1, name_codepoint_range, name] <=>
+ [other.singleton ? 0 : 1, other.name_codepoint_range, other.name]
end
def == other # :nodoc:
@@ -415,4 +415,16 @@ class RDoc::MethodAttr < RDoc::CodeObject
end
end
+ def name_codepoint_range # :nodoc:
+ case name.codepoints[0]
+ when 0..64 # anything below "A"
+ 1
+ when 91..96 # the symbols between "Z" and "a"
+ 2
+ when 123..126 # 7-bit symbols above "z": "{", "|", "}", "~"
+ 3
+ else # everythig else can be sorted as normal
+ 4
+ end
+ end
end