diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-10-17 13:26:37 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-10-17 13:26:37 +0900 |
| commit | 4122c320bb8a81ff66eae72e25eda8af6c768683 (patch) | |
| tree | 9341b934fde1a11db5233636710cd9084c0844af /mrbgems/mruby-string-ext | |
| parent | db8265f428175ac19885e14c5b1beb3e8f6c5af4 (diff) | |
| download | mruby-4122c320bb8a81ff66eae72e25eda8af6c768683.tar.gz mruby-4122c320bb8a81ff66eae72e25eda8af6c768683.zip | |
Add `{String,Symbol}#casecmp?`; CRuby2.4
Diffstat (limited to 'mrbgems/mruby-string-ext')
| -rw-r--r-- | mrbgems/mruby-string-ext/mrblib/string.rb | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/mrbgems/mruby-string-ext/mrblib/string.rb b/mrbgems/mruby-string-ext/mrblib/string.rb index c3a7eb380..cb36d9a48 100644 --- a/mrbgems/mruby-string-ext/mrblib/string.rb +++ b/mrbgems/mruby-string-ext/mrblib/string.rb @@ -144,7 +144,20 @@ class String def casecmp(str) self.downcase <=> str.to_str.downcase rescue NoMethodError - raise TypeError, "no implicit conversion of #{str.class} into String" + nil + end + + ## + # call-seq: + # str.casecmp?(other) -> true, false, or nil + # + # Returns true if str and other_str are equal after case folding, + # false if they are not equal, and nil if other_str is not a string. + + def casecmp?(str) + c = self.casecmp(str) + return nil if c.nil? + return c == 0 end def partition(sep) |
