Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
ENV.inspect
ENV.inspect → a_string
hash.c
View on GitHub ↗
static VALUE
env_inspect(VALUE _)
{
VALUE i;
VALUE str = rb_str_buf_new2("{");
ENV_LOCK();
{
char **env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
if (env != environ) {
rb_str_buf_cat2(str, ", ");
}
if (s) {
rb_str_buf_cat2(str, "\"");
rb_str_buf_cat(str, *env, s-*env);
rb_str_buf_cat2(str, "\"=>");
i = rb_inspect(rb_str_new2(s+1));
rb_str_buf_append(str, i);
}
env++;
}
FREE_ENVIRON(environ);
}
ENV_UNLOCK();
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\"}"