Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Hash#has_key?
(::Hash::_Key key) -> bool
has_key?(p1)
hash.c
View on GitHub ↗
VALUE
rb_hash_has_key(VALUE hash, VALUE key)
{
return RBOOL(hash_stlike_lookup(hash, key, NULL));
}
Alias of #include?
Returns whether key is a key in self:
Example
h = {foo: 0, bar: 1, baz: 2} h.include?(:bar) # => true h.include?(:BAR) # => false
Related: Methods for Querying.