Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
ENV.value?
ENV.value?(value) → true or false
ENV.has_value?(value) → true or false
hash.c
View on GitHub ↗
static VALUE
env_has_value(VALUE dmy, VALUE obj)
{
obj = rb_check_string_type(obj);
if (NIL_P(obj)) return Qnil;
VALUE ret = Qfalse;
ENV_LOCKING() {
char **env = GET_ENVIRON(environ);
while (*env) {
char *s = strchr(*env, '=');
if (s++) {
rb_len_t len = strlen(s);
if (RSTRING_LEN(obj) == len && strncmp(s, RSTRING_PTR(obj), len) == 0) {
ret = Qtrue;
break;
}
}
env++;
}
FREE_ENVIRON(environ);
}
return ret;
}
Returns true if value is the value for some environment variable name, false otherwise:
Example
ENV.replace('foo' => '0', 'bar' => '1') ENV.value?('0') # => true ENV.has_value?('0') # => true ENV.value?('2') # => false ENV.has_value?('2') # => false