Method: String.try_convert

Defined in:
string.c

.try_convert(obj) ⇒ String?

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

Returns:



1657
1658
1659
1660
1661
# File 'string.c', line 1657

static VALUE
rb_str_s_try_convert(VALUE dummy, VALUE str)
{
    return rb_check_string_type(str);
}