Created
September 17, 2012 02:31
-
-
Save colemanfoley/3735256 to your computer and use it in GitHub Desktop.
Translates English word to Pig Latin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#The main method, it takes a string that is an English word and returns that word in Pig Latin. | |
#All words have "ay" appended to them in the line just before the return statement. If the word | |
#begins with a vowel, it is sent to the << "ay" line unmodified. | |
#If it is exactly three letters long, the second two characters of english_word are made the first | |
#two of pig_latin_word, then the first letter of english_word is made the third character of | |
#pig_latin_word. Then the word is ready to get the << "ay" treatment. | |
def translate(english_word) | |
if is_vowel?(english_word[0]) | |
pig_latin_word = english_word | |
elsif english_word.length == 3 | |
pig_latin_word[0,1] = english_word[1,2] | |
pig_latin_word[2] = english_word[0] | |
end | |
pig_latin_word << "ay" | |
return pig_latin_word | |
end | |
#Helper method for translate that determines if a character is a vowel or not, returning a boolean | |
def is_vowel?(string) | |
string = string.downcase | |
if string == "a" | |
return true | |
elsif string == "e" | |
return true | |
elsif string == "i" | |
return true | |
elsif string == "o" | |
return true | |
elsif string == "u" | |
return true | |
else | |
return false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment