End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
Regexp.try_convert
Regexp.try_convert(object) → regexp or nil
re.c
View on GitHub ↗
static VALUE
rb_reg_s_try_convert(VALUE dummy, VALUE re)
{
return rb_check_regexp_type(re);
}
Returns object if it is a regexp:
Example
Regexp.try_convert(/re/) # => /re/
Otherwise if object responds to :to_regexp, calls object.to_regexp and returns the result.
Returns nil if object does not respond to :to_regexp.
Example
Regexp.try_convert('re') # => nil
Raises an exception unless object.to_regexp returns a regexp.