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.
parent e207d5af
class String 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: # call-seq:
# string.clear -> string # string.clear -> string
......
...@@ -4,13 +4,6 @@ ...@@ -4,13 +4,6 @@
UTF8STRING = ("\343\201\202".size == 1) 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 assert('String#getbyte') do
str1 = "hello" str1 = "hello"
bytes1 = [104, 101, 108, 108, 111] bytes1 = [104, 101, 108, 108, 111]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment