summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-07-20 19:19:23 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-08-02 16:40:12 +0900
commitec3f59309e3f08339c4c76a6881901580801d6cd (patch)
treed5709cd6b5b17d4582a61d2492087fbd681db7d8 /hash.c
parent3e4fedca4e0b068908137d44bcf5a567cb8445d0 (diff)
[Bug #17767] Now `ENV.clone` raises `TypeError` as well as `ENV.dup`
One year ago, the former method has been deprecated while the latter has become an error. Then the 3.1 released, it is enough time to make also the former an error.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6155
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/hash.c b/hash.c
index 69a768d4ce..8c20791ede 100644
--- a/hash.c
+++ b/hash.c
@@ -6639,31 +6639,26 @@ env_update(int argc, VALUE *argv, VALUE env)
return env;
}
+NORETURN(static VALUE env_clone(int, VALUE *, VALUE));
/*
* call-seq:
- * ENV.clone(freeze: nil) -> ENV
+ * ENV.clone(freeze: nil) # raises TypeError
*
- * Returns ENV itself, and warns because ENV is a wrapper for the
- * process-wide environment variables and a clone is useless.
- * If +freeze+ keyword is given and not +nil+ or +false+, raises ArgumentError.
- * If +freeze+ keyword is given and +true+, raises TypeError, as ENV storage
- * cannot be frozen.
+ * Raises TypeError, because ENV is a wrapper for the process-wide
+ * environment variables and a clone is useless.
+ * Use #to_h to get a copy of ENV data as a hash.
*/
static VALUE
env_clone(int argc, VALUE *argv, VALUE obj)
{
if (argc) {
- VALUE opt, kwfreeze;
+ VALUE opt;
if (rb_scan_args(argc, argv, "0:", &opt) < argc) {
- kwfreeze = rb_get_freeze_opt(1, &opt);
- if (RTEST(kwfreeze)) {
- rb_raise(rb_eTypeError, "cannot freeze ENV");
- }
+ rb_get_freeze_opt(1, &opt);
}
}
- rb_warn_deprecated("ENV.clone", "ENV.to_h");
- return envtbl;
+ rb_raise(rb_eTypeError, "Cannot clone ENV, use ENV.to_h to get a copy of ENV as a hash");
}
NORETURN(static VALUE env_dup(VALUE));