diff options
author | Jeremy Evans <[email protected]> | 2019-06-14 16:53:42 -0700 |
---|---|---|
committer | Jeremy Evans <[email protected]> | 2019-07-01 12:39:06 -0700 |
commit | f53d7e4bfd604be6f8131c5460c29f4af16da117 (patch) | |
tree | c971256baaed293e95d0a381bc524e6ec2113199 /hash.c | |
parent | 93328b5237c515878dacfa7350688b016333225d (diff) |
Raise TypeError if calling ENV.freeze
Previously, you could call ENV.freeze, but it would not have
the desired effect, as you could still modify ENV.
Fixes [Bug #15920]
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -5701,6 +5701,20 @@ env_reject(void) /* * call-seq: + * ENV.freeze -> raises TypeError + * + * Ruby does not allow ENV to be frozen, so calling ENV.freeze + * raises TypeError. + */ +static VALUE +env_freeze(VALUE self) +{ + rb_raise(rb_eTypeError, "cannot freeze ENV"); + return self; /* Not reached */ +} + +/* + * call-seq: * ENV.shift -> Array or nil * * Removes an environment variable name-value pair from ENV and returns it as @@ -6058,6 +6072,7 @@ Init_Hash(void) rb_define_singleton_method(envtbl, "filter", env_select, 0); rb_define_singleton_method(envtbl, "filter!", env_select_bang, 0); rb_define_singleton_method(envtbl, "shift", env_shift, 0); + rb_define_singleton_method(envtbl, "freeze", env_freeze, 0); rb_define_singleton_method(envtbl, "invert", env_invert, 0); rb_define_singleton_method(envtbl, "replace", env_replace, 1); rb_define_singleton_method(envtbl, "update", env_update, 1); |