Exception: FrozenError

Inherits:
RuntimeError show all
Defined in:
error.c,
error.c

Overview

Raised when there is an attempt to modify a frozen object.

[1, 2, 3].freeze << 4

raises the exception:

FrozenError: can't modify frozen Array

Instance Method Summary collapse

Methods inherited from Exception

#==, #backtrace, #backtrace_locations, #cause, #exception, exception, #full_message, #inspect, #message, #set_backtrace, #to_s, to_tty?

Constructor Details

#new(msg = nil, receiver: nil) ⇒ Object

Construct a new FrozenError exception. If given the receiver parameter may subsequently be examined using the FrozenError#receiver method.

a = [].freeze
raise FrozenError.new("can't modify frozen array", receiver: a)

1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
# File 'error.c', line 1623

static VALUE
frozen_err_initialize(int argc, VALUE *argv, VALUE self)
{
    ID keywords[1];
    VALUE values[numberof(keywords)], options;

    argc = rb_scan_args(argc, argv, "*:", NULL, &options);
    keywords[0] = id_receiver;
    rb_get_kwargs(options, keywords, 0, numberof(values), values);
    rb_call_super(argc, argv);
    err_init_recv(self, values[0]);
    return self;
}

Instance Method Details

#receiverObject

Return the receiver associated with this FrozenError exception.

Returns: