So I fixed the rest of the macro (as it can’t use return either):
macro article(word)
{% word = word.downcase %}
{% vowel_sound = ["hour", "honest", "honor", "heir"] %}
{% consonant_sound = ["university", "unicorn", "use", "european", "one", "ouja"] %}
{% result = nil %}
{% result = "an" if vowel_sound.includes? word %}
{% result = 'a' if consonant_sound.includes? word %}
{% first_letter = word[0..0] %}
{% if !result
result = (['a', 'e', 'i', 'o', 'u'].includes?(first_letter) ? "an" : 'a')
end %}
{{ [result, word] }}
end
But now when it does not hit one of the exceptions (vowel_sound or consonant_sound), I’ll always get ‘a’. So I assume what happens is the first_letter is a range at this point..? Don’t I run into the same problem as with a string now?
The problem is that your array of vowels contains chars, but the [] operator always returns a new string instead of a char, which will always give a false when compared with the chars in your vowel array.
Changing your code to result = (["a", "e", "i", "o", "u"].includes?(first_letter) ? "an" : "a") will make it work.