RCR 208: Introduce freeze levels
Submitted by Phil Tomson (Sat Feb 07 17:02:38 UTC 2004)
Abstract
Introduce freeze levels. The default level would function exactly as it does now by preventing any modifications to objects. By specifying an argument to the Object#freeze method, different levels of 'freezing' could be created.
Problem
Some Ruby users consider any changes to built-in Ruby classes/modules/objects to be dangerous - in general they can use the current 'freeze' method as-is to make sure that no changes can be made.
Other users feel that allowing changes to be made to classes/modules/objects to be a very beneficial feature of Ruby. However, they might feel that redefining built-in methods is a 'dangerous' practice.
Proposal
The proposal is to introduce a new freeze level that would allow new methods to be defined for an object, but would not allow redefining already existing methods in the object.
Analysis
This proposal would allow for an extra level of safety. Currently, freeze in an all-or-nothing proposition: if you freeze an object you can't add new methods to the object. The new freeze level would not allow the user to redefine methods on the object,but they would be able to add new ones.
Implementation
An optional argument would be added to Object#freeze to indicate the new level.
Object#freeze(level=0)
#level 0 is the default
#level 1 is the new level
Or, alternately, a new freeze method could be added to Object, perhaps called:
Object#partial_freeze
I think freeze is mainly concerned with instance state modification. This functionaliy (especially restricting method changes to adding methods) seems more like a security feature. So probably $SAFE is a better place to deal with this.
robert
|
Strongly opposed |
0 |
Opposed |
3 |
Neutral |
2 |
In favor |
1 |
Strongly advocate |
0 |
|
RCRchive copyright © David Alan Black, 2003-2005.
Powered by .
robert