Can't modify literal regexp: why?

I was just curious as to why this is illegal.

Example:
$ irb

/blah/.clone
SecurityError: can’t modify literal regexp
from (irb):1:in initialize_copy' from (irb):1:inclone’
from (irb):1

Regexp.new(/blah/).clone is perfectly OK. What’s insecure about cloning
a literal regex?

Jeremy S. wrote:

I was just curious as to why this is illegal.

Example:
$ irb

/blah/.clone
SecurityError: can’t modify literal regexp
from (irb):1:in initialize_copy' from (irb):1:inclone’
from (irb):1

Regexp.new(/blah/).clone is perfectly OK. What’s insecure about cloning
a literal regex?

(/blah/).clone

Hi,

At Wed, 14 Nov 2007 05:56:12 +0900,
Jeremy S. wrote in [ruby-talk:278872]:

Regexp.new(/blah/).clone is perfectly OK. What’s insecure about cloning
a literal regex?

It is to prohibit /blah/.initialize_copy(/foobar/). You may
know, /blah/.dup works.

Nobuyoshi N. wrote:

Hi,

At Wed, 14 Nov 2007 05:56:12 +0900,
Jeremy S. wrote in [ruby-talk:278872]:

Regexp.new(/blah/).clone is perfectly OK. What’s insecure about cloning
a literal regex?

It is to prohibit /blah/.initialize_copy(/foobar/). You may
know, /blah/.dup works.

Thanks for the info. Anyone know why it’s prohibited? Just curious.

On Nov 14, 2007, at 06:48 , Jeremy S. wrote:

It is to prohibit /blah/.initialize_copy(/foobar/). You may
know, /blah/.dup works.

Thanks for the info. Anyone know why it’s prohibited? Just
curious.

x = /x/.dup
x.send :initialize_copy, /y/
p x # => /y/