mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Implement Symbol#casecmp
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user