ruby picture

RCR 207: --freeze commandline option

Submitted by Phil Tomson (Sat Feb 07 17:02:46 UTC 2004)

Abstract

Introduce a new commandline option that when invoked would freeze all built-in Ruby classes and modules.

Problem

Some Ruby users (and potential Ruby users) complain that being able to modify built-in classes and modules is 'dangerous'. Most Ruby users like having the freedom to (carefully) add methods to built-in classes and modules.

Proposal

Introduce a new commandline argument to the Ruby executable called '--freeze' that would freeze all built-in classes and modules prior to interpreting user code.

Analysis

This proposal would satisfy both groups of users: those who feel the need for more 'safety' and those who prefer the freedom to add/change methods. Users who do not like changes to internal classes could use the '--freeze' commandline option. It could also be used as an analysis tool to determine if the code being run is making changes to built-in libraries.

Implementation

if the commandline option '--freeze' is specified on the Ruby commandline, the following code (or equivilent functionality) would be run prior to running the user's script:
  ObjectSpace.each_object(Class) {|c| c.freeze }
 ObjectSpace.each_object(Module) {|m| m.freeze }
ruby picture
Comments Current voting
I am opposed because this is not Java and Ruby's command-line arguments (and C code) should not be cluttered up by things to make it into Java. This would also destroy libraries like mathn.

Anyone who, for some strange reason, needs what you propose can easily use the two lines of code that you do, assuming that they work. They can also choose to use another language, as Ruby is likely not for them.


Strongly opposed 2
Opposed 4
Neutral 0
In favor 0
Strongly advocate 2
ruby picture
If you have registered at RCRchive, you may now sign in below. If you have not registered, you may sign up for a username and password. Registering enables you to submit new RCRs, and vote and leave comments on existing RCRs.
Your username:
Your password:

ruby picture

Powered by .