instance method
Regexp#to_s
() -> ::String
to_s → string
re.c
View on GitHub ↗
static VALUE
rb_reg_to_s(VALUE re)
{
return rb_reg_str_with_term(re, '/');
}
Returns a string showing the options and string of self:
Example
r0 = /ab+c/ix s0 = r0.to_s # => "(?ix-m:ab+c)"
The returned string may be used as an argument to Regexp.new, or as interpolated text for a Regexp interpolation:
Example
r1 = Regexp.new(s0) # => /(?ix-m:ab+c)/ r2 = /#{s0}/ # => /(?ix-m:ab+c)/
Note that r1 and r2 are not equal to r0 because their original strings are different:
Example
r0 == r1 # => false r0.source # => "ab+c" r1.source # => "(?ix-m:ab+c)"
Related: Regexp#inspect.