Method: String.try_convert

Defined in:
string.c

.try_convert(object) ⇒ Object?

If object is a String object, returns object.

Otherwise if object responds to :to_str, calls object.to_str and returns the result.

Returns nil if object does not respond to :to_str

Raises an exception unless object.to_str returns a String object.

Returns:


2456
2457
2458
2459
2460
# File 'string.c', line 2456

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