Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
ENV.inspect
ENV.inspect → a_string
hash.c
View on GitHub ↗
static VALUE
env_inspect(VALUE _)
{
VALUE str = rb_str_buf_new2("{");
rb_encoding *enc = env_encoding();
ENV_LOCKING() {
char **env = GET_ENVIRON(environ);
while (*env) {
const char *s = strchr(*env, '=');
if (env != environ) {
rb_str_buf_cat2(str, ", ");
}
if (s) {
rb_str_buf_append(str, rb_str_inspect(env_enc_str_new(*env, s-*env, enc)));
rb_str_buf_cat2(str, " => ");
s++;
rb_str_buf_append(str, rb_str_inspect(env_enc_str_new(s, strlen(s), enc)));
}
env++;
}
FREE_ENVIRON(environ);
}
rb_str_buf_cat2(str, "}");
return str;
}
Returns the contents of the environment as a String:
Example
ENV.replace('foo' => '0', 'bar' => '1') ENV.inspect # => "{\"bar\"=>\"1\", \"foo\"=>\"0\"}"