VOOZH about

URL: https://apidock.com/ruby/String/try_convert/class

⇱ String.try_convert - APIdock


method

try_convert

ruby latest stable - Class: String
try_convert(p1)
public

Try to convert obj into a String, using to_str method. Returns converted string or nil if obj cannot be converted for any reason.

String.try_convert("str") #=> "str"
String.try_convert(/re/) #=> nil
static VALUE
rb_str_s_try_convert(VALUE dummy, VALUE str)
{
 return rb_check_string_type(str);
}

Related methods