Implement Symbol#casecmp

This commit is contained in:
ksss
2014-04-20 13:37:29 +09:00
parent 44cc51fef7
commit bb52324bd9
2 changed files with 18 additions and 0 deletions
+11
View File
@@ -47,6 +47,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