Skip to content

Instantly share code, notes, and snippets.

@bcamarda
Created June 21, 2012 00:21
Show Gist options
  • Save bcamarda/2963112 to your computer and use it in GitHub Desktop.
Save bcamarda/2963112 to your computer and use it in GitHub Desktop.
Pig Latin
def translate(string)
vowel = ["a", "e", "i", "o", "u", "y"]
if ((vowel.include? string[0]) == false) && ((vowel.include? string[1]) == false) && ((vowel.include? string[2]) == false)
string = string[3..-1] + string[0..2] + "ay"
elsif ((vowel.include? string[0]) == false) && ((vowel.include? string[1]) == false)
string = string[2..-1] + string[0..1] + "ay"
elsif (vowel.include? string[0]) == true
string = string + "ay"
elsif string[0..1] == "qu"
string = string[2..-1] + string[0..1] + "ay"
else
string = string[1..-1].+string[0].+"ay"
end
puts string
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment