Skip to content

Instantly share code, notes, and snippets.

@shilovk
Forked from davidbella/vowels
Created November 20, 2019 17:57
Show Gist options
  • Save shilovk/53ad0cace80c79fd298485764e43e58e to your computer and use it in GitHub Desktop.
Save shilovk/53ad0cace80c79fd298485764e43e58e to your computer and use it in GitHub Desktop.
Ruby: All about finding vowels
def is_vowel_elsif(letter)
if letter == "a"
true
elsif letter == "e"
true
elsif letter == "i"
true
elsif letter == "o"
true
elsif letter == "u"
true
else
false
end
end
puts is_vowel_elsif("a")
def is_vowel_case(letter)
case letter
when "a"
true
when "e"
true
when "i"
true
when "o"
true
when "u"
true
else
false
end
end
puts is_vowel_case("e")
def is_vowel_one_if(letter)
if letter == "a" || letter == "e" || letter == "i" || letter == "o" || letter == "u"
return true
end
false
end
puts is_vowel_one_if("i")
def is_vowel_no_if(letter)
"aeiou".include?(letter)
end
puts is_vowel_no_if("o")
def is_vowel_array(letter)
["a", "e", "i", "o", "u"].include?(letter)
end
puts is_vowel_array("u")
def first_vowel(string)
string.match(/a|e|i|o|u/)
end
puts first_vowel("first_vowel")
def first_vowel_index(string)
string.index(first_vowel(string).to_s)
end
puts first_vowel_index("first_vowel_index")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment