I have a config YAML file with the following array:
EMAILS: ['email1@example.com', 'email2@example.com', 'email3@example.com']
And then I want to search inside this YAML array for a particular string, say “email1@example.com”.
I use the following ruby code:
if CONFIG[:EMAILS].include?("email1@example.com")
return true
else
return false
end
However, this always returns false.
I can PUTS the CONFIG[:EMAIL] array fine.
Can anyone suggest what I’m doing wrong.
You’re using a symbol, while the YAML hash uses strings as keys. This should work:
Which, by the way, is equivalent to simply