Method: Regexp#to_s
- Defined in:
- re.c
#to_s ⇒ String
Returns a string showing the options and string of self
:
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:
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:
r0 == r1 # => false
r0.source # => "ab+c"
r1.source # => "(?ix-m:ab+c)"
Related: Regexp#inspect.
564 565 566 567 568 |
# File 're.c', line 564
static VALUE
rb_reg_to_s(VALUE re)
{
return rb_reg_str_with_term(re, '/');
}
|