Method: Object#freeze

Defined in:
object.c

#freezeObject

Prevents further modifications to obj. A FrozenError will be raised if modification is attempted. There is no way to unfreeze a frozen object. See also Object#frozen?.

This method returns self.

a = [ "a", "b", "c" ]
a.freeze
a << "z"

produces:

prog.rb:3:in `<<': can't modify frozen Array (FrozenError)
	from prog.rb:3

Objects of the following classes are always frozen: Integer, Float, Symbol.

Returns:



1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
# File 'object.c', line 1318

VALUE
rb_obj_freeze(VALUE obj)
{
    if (!OBJ_FROZEN(obj)) {
        OBJ_FREEZE(obj);
        if (SPECIAL_CONST_P(obj)) {
            rb_bug("special consts should be frozen.");
        }
    }
    return obj;
}