Skip to content

Instantly share code, notes, and snippets.

@andersr
Created October 11, 2013 15:14
Show Gist options
  • Save andersr/6936448 to your computer and use it in GitHub Desktop.
Save andersr/6936448 to your computer and use it in GitHub Desktop.
# Let's go back to the exercise where we determined what is and isn't a vowel.
# With ruby, there's always more than one way to do something and get the same result.
# Assuming vowels a,e,i,o,u:
VOWELS = ["a","e","i","o","u"]
# Write a method that returns whether a given letter is a vowel, using if and elsif
def is_a_vowel?(letter)
if letter == "a"
end
# Write a method that returns whether a given letter is a vowel, using case
def is_a_vowel?(letter)
case letter
when "a"
true
when "b"
true
else
false
end
end
# Write a method that returns whether a given letter is a vowel, using if with no else, all on a single line
def is_a_vowel?(letter)
true if letter == "a" | "e" | "i" | "o" | "u"
end
# Write a method that returns whether a given letter is a vowel without
# using if or case while all on a single line
def is_a_vowel?(letter)
letter.include?(/a|e|o|i|u/)
end
# Write a method that returns whether a given letter is a vowel
def is_a_vowel?(letter)
VOWELS.each do |vowel|
end
end
# without checking equality, or the use of if, using the array of vowels
# Write a method that will evaluate a string and return the first vowel found in the string, if any
# Write a method that will evaluate a string and return the ordinal position
#(index) of the string where the first vowel is found, if any
# hint: remember that every line of ruby code has a return value,
#and that a method will return the result of the last operation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment