summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-symbol-ext
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-10-17 13:26:37 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2017-10-17 13:26:37 +0900
commit4122c320bb8a81ff66eae72e25eda8af6c768683 (patch)
tree9341b934fde1a11db5233636710cd9084c0844af /mrbgems/mruby-symbol-ext
parentdb8265f428175ac19885e14c5b1beb3e8f6c5af4 (diff)
downloadmruby-4122c320bb8a81ff66eae72e25eda8af6c768683.tar.gz
mruby-4122c320bb8a81ff66eae72e25eda8af6c768683.zip
Add `{String,Symbol}#casecmp?`; CRuby2.4
Diffstat (limited to 'mrbgems/mruby-symbol-ext')
-rw-r--r--mrbgems/mruby-symbol-ext/mrblib/symbol.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/mrbgems/mruby-symbol-ext/mrblib/symbol.rb b/mrbgems/mruby-symbol-ext/mrblib/symbol.rb
index 1e3d24b80..28cce3156 100644
--- a/mrbgems/mruby-symbol-ext/mrblib/symbol.rb
+++ b/mrbgems/mruby-symbol-ext/mrblib/symbol.rb
@@ -48,10 +48,23 @@ class Symbol
def casecmp(other)
return nil unless other.kind_of?(Symbol)
lhs = self.to_s; lhs.upcase!
- rhs = other.to_s; rhs.upcase!
+ rhs = other.to_s.upcase
lhs <=> rhs
end
+ ##
+ # call-seq:
+ # sym.casecmp?(other) -> true, false, or nil
+ #
+ # Returns true if sym and other_sym are equal after case folding,
+ # false if they are not equal, and nil if other_sym is not a string.
+
+ def casecmp?(sym)
+ c = self.casecmp(sym)
+ return nil if c.nil?
+ return c == 0
+ end
+
#
# call-seq:
# sym.empty? -> true or false