Skip to content

Instantly share code, notes, and snippets.

@kmandreza
Created June 28, 2012 19:28
Show Gist options
  • Save kmandreza/3013361 to your computer and use it in GitHub Desktop.
Save kmandreza/3013361 to your computer and use it in GitHub Desktop.
Pig Latin
def translate(word)
if word[0] == "a" || word[0] == "e" || word[0] == "i" || word[0] == "o" || word[0] == "u"
word << "ay"
elsif word[0..1] == "qu"
f = (word[0..1] << 'ay')
word[0..1] = ""
word << f
elsif word[1] == "a" || word[1] == "e" || word[1] == "i" || word[1] == "o" || word[1] == "u"
f = (word[0] << 'ay')
word[0] = ""
word << f
elsif word[2] == "a" || word[2] == "e" || word[2] == "i" || word[2] == "o" || word[2] == "u"
f = (word[0..1] << 'ay')
word[0..1] = ""
word << f
elsif word[3] == "a" || word[3] == "e" || word[3] == "i" || word[3] == "o" || word[3] == "u"
f = (word[0..2] << 'ay')
word[0..2] = ""
word
word << f
end
end
puts translate("quiet")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment