Method: Regexp.try_convert
- Defined in:
- re.c
.try_convert(object) ⇒ Regexp?
Returns object if it is a regexp:
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.
Regexp.try_convert('re') # => nil
Raises an exception unless object.to_regexp returns a regexp.
4233 4234 4235 4236 4237 |
# File 're.c', line 4233 static VALUE rb_reg_s_try_convert(VALUE dummy, VALUE re) { return rb_check_regexp_type(re); } |