Skip to content

Instantly share code, notes, and snippets.

@lordhumunguz
Created March 8, 2013 09:26
Show Gist options
  • Save lordhumunguz/5115259 to your computer and use it in GitHub Desktop.
Save lordhumunguz/5115259 to your computer and use it in GitHub Desktop.
This gist has been created from CodeCred.me
def pig_latin(string1)
string1.to_s.downcase!
if #If a word begins with a vowel (aeiou), add 'ay' to the end.
string1[0] == 'a' || string1[0] == 'e' || string1[0] == 'i' || string1[0] == 'o' || string1[0] == "u"
string1 += 'ay'
elsif #If a word begins with 'qu', move the 'qu' to the end of the word and add 'ay' after it.
string1[0,2] == 'qu'
string1 = string1.insert(-1, 'qu') + 'ay'
string1 = string1[2..-1]
else #If a word begins with a consonant, move it to the end of the word and add 'ay' after it.
letter1 = string1[0]
string1 = string1.insert(-1, letter1)
string1 = string1[1..-1]
#NEED HELP
#If a word begins with multiple consonants, move all of them to the end of the word and add 'ay' after them. (easier version is to look @ only first 3 letters)
end
end
#TESTS
puts pig_latin('apple')
puts pig_latin('zonga')
puts pig_latin('qunga')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment