Skip to content

Instantly share code, notes, and snippets.

@mfpiccolo
Last active December 11, 2015 06:09
Show Gist options
  • Save mfpiccolo/4557462 to your computer and use it in GitHub Desktop.
Save mfpiccolo/4557462 to your computer and use it in GitHub Desktop.
Enter a word as the argument for translate_into_pig_latin and the program will translate it into pig latin.
def translate_into_pig_latin(word1)
vowels = ["a","e","i","o","u"]
consonants = ["q","w","r","t","y","p","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"]
if vowels.include?(word1[0])
word1 << "ay"
else
if word1[0..1] == "qu"
word1[2..word1.length] << "qu" << "ay"
elsif consonants.include?(word1[0]) && consonants.include?(word1[1]) && consonants.include?(word1[2])
word1[3..word1.length] << word1[0..2] << "ay"
elsif consonants.include?(word1[0]) && consonants.include?(word1[1])
word1[2..word1.length] << word1[0..1] << "ay"
elsif consonants.include?(word1[0])
word1[1..word1.length] << word1[0] << "ay"
elsif word1.include?(" ")
'This program only runs single words...for now.'
else
'I dont think that is a word.'
end
end
end
puts "'#{translate_into_pig_latin('apple')}' should equal 'appleay'"
puts "'#{translate_into_pig_latin('piglet')}' should equal 'igletpay'"
puts "'#{translate_into_pig_latin('quote')}' should equal 'otequay'"
puts "'#{translate_into_pig_latin('strap')}' should equal 'apstray'"
puts "'#{translate_into_pig_latin('check')}' should equal 'ekchay'"
puts "'#{translate_into_pig_latin('^well hello there')}' should equal 'This program only runs single words...for now.'"
puts "'#{translate_into_pig_latin('^#%@&')}' should equal 'I dont think that is a word.'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment