Warren Brown wrote:

>>Is there some trick to modify the casefold attribute of a Regexp
>>object after it's been instantiated?
>     No, Regexps are immutable - you can't change them.

Oh, you can:

irb(main):001:0> re = /./; "hello world!".gsub(re) { |m| 
re.send(:initialize, /#{re}./); "<#{m}>" }
=> "<h><el><lo ><worl>d!" 


And that behavior is needed in some cases because there is no #to_regexp.

And thank you for mentioning Regexp#source -- I didn't know about it yet.

Regards,
Florian Gross