Code:
def vowel_start(word)
if (word[0] == 'a' || word[0] == 'e' || word[0] == 'i' || word[0] == 'o' || word[0] == 'u')
return true
else
return false
end
end
This is unidiomatic ruby in almost every way, so I'll try to help:
"vowel_start" -- Make your names sound as close to natural English as possible. "starts_with_vowel" is clearer than "vowel_start"
You should only use "return" when you need to exit early. Here, your function is a single expression, so you could remove both returns:
Code:
def starts_with_vowel(word)
if (word[0] == 'a' || word[0] == 'e' || word[0] == 'i' || word[0] == 'o' || word[0] == 'u')
true
else
false
end
end
But why stop there? You are returning "true" if the if clause is true, false otherwise. Just make your body the if clause itself:
Code:
def starts_with_vowel(word)
(word[0] == 'a' || word[0] == 'e' || word[0] == 'i' || word[0] == 'o' || word[0] == 'u')
end
Just looking at this, you can know with 95% certainty there is a better way. Ruby is optimized for conciseness. This kind of repetition for such a common task will have a shortcut:
Code:
def starts_with_vowel(word)
'aeiou'.include? word[0]
end
This is now acceptable ruby. As for your other function with the until loop, I'll let you fix that, but know that using loops that way is nearly always a "writing C/java in ruby" code smell, and you can find a better way.