Skip to content
class method

Regexp.try_convert

(::Regexp | ::Regexp::_ToRegexp regexp_like) -> ::Regexp
(untyped other) -> ::Regexp?
Regexp.try_convert(object) → regexp or nil

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.

See also .timeout= .union .timeout #== also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0