freeze

obj.freeze â obj
Instance Public methods

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

This method returns self.

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

produces:

1
2
prog.rb:3:in `<<': can't modify frozen array (RuntimeError)
 from prog.rb:3
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.