Mega Code Archive

 
Categories / Ruby / Hash
 

Checking for the presence of keys in a hash

h = { :a => 1, :b => 2 } h.key?(:a)       # true: :a is a key in h h.has_key?(:b)   # true: has_key? is a synonym for key? h.include?(:c)   # false: include? is another synonym h.member?(:d)    # false: member? is yet another synonym