Check if a key exists in a hash
Check if a key exists in a hash
1
2
3
4
5
6
# create hash
my_dict = { "apples" => 3, "pears" => 2 }
# check if a key exists
puts my_dict.has_key?("apples") # true
puts my_dict.has_key?("oranges") # false
Sources
This post is licensed under CC BY 4.0 by the author.