Method: Object#freeze
- Defined in:
- object.c
#freeze ⇒ Object
Prevents further modifications to obj. A TypeError will be raised if modification is attempted. There is no way to unfreeze a frozen object. See also Object#frozen?.
a = [ "a", "b", "c" ]
a.freeze
a << "z"
produces:
prog.rb:3:in `<<': can't modify frozen array (TypeError)
from prog.rb:3
724 725 726 |
# File 'object.c', line 724 VALUE rb_obj_freeze(obj) VALUE obj; |