Merge pull request #2089 from ksss/sym-casecmp

Implement Symbol#casecmp
This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-04-20 21:30:46 +09:00
2 changed files with 18 additions and 0 deletions
+11
View File
@@ -48,6 +48,17 @@ class Symbol
self.to_s.upcase.intern
end
##
# call-seq:
# sym.casecmp(other) -> -1, 0, +1 or nil
#
# Case-insensitive version of <code>Symbol#<=></code>.
def casecmp(other)
return nil unless other.kind_of?(Symbol)
self.to_s.upcase <=> other.to_s.upcase
end
#
# call-seq:
# sym.empty? -> true or false
+7
View File
@@ -29,6 +29,13 @@ assert("Symbol#upcase") do
assert_equal :HELLO, :hEllO.upcase
end
assert("Symbol#casecmp") do
assert_equal 0, :HELLO.casecmp(:hEllO)
assert_equal 1, :HELLO.casecmp(:hEllN)
assert_equal -1, :HELLO.casecmp(:hEllP)
assert_nil :HELLO.casecmp("hEllO")
end
assert("Symbol#empty?") do
assert_true :''.empty?
end