mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Removed String#try_convert method from mruby-string-ext gem.
Because `try_convert` method rarely used in production. For mruby users, we have `__to_str` utility method to check string type.
This commit is contained in:
@@ -1,24 +1,5 @@
|
||||
class String
|
||||
|
||||
##
|
||||
# call-seq:
|
||||
# String.try_convert(obj) -> string or nil
|
||||
#
|
||||
# Try to convert <i>obj</i> into a String, using to_str method.
|
||||
# Returns converted string or nil if <i>obj</i> cannot be converted
|
||||
# for any reason.
|
||||
#
|
||||
# String.try_convert("str") #=> "str"
|
||||
# String.try_convert(/re/) #=> nil
|
||||
#
|
||||
def self.try_convert(obj)
|
||||
if self === obj
|
||||
obj
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# call-seq:
|
||||
# string.clear -> string
|
||||
|
||||
@@ -4,13 +4,6 @@
|
||||
|
||||
UTF8STRING = ("\343\201\202".size == 1)
|
||||
|
||||
assert('String.try_convert') do
|
||||
assert_nil String.try_convert(nil)
|
||||
assert_nil String.try_convert(:foo)
|
||||
assert_equal "", String.try_convert("")
|
||||
assert_equal "1,2,3", String.try_convert("1,2,3")
|
||||
end
|
||||
|
||||
assert('String#getbyte') do
|
||||
str1 = "hello"
|
||||
bytes1 = [104, 101, 108, 108, 111]
|
||||
|
||||
Reference in New Issue
Block a user