Skip to content

Instantly share code, notes, and snippets.

@Solnse
Created December 15, 2012 00:01
Show Gist options
  • Save Solnse/4289739 to your computer and use it in GitHub Desktop.
Save Solnse/4289739 to your computer and use it in GitHub Desktop.
def translate(word)
word_list = word.split(/ /)
letters = ('a'..'z').to_a
vowels = ['a', 'e', 'i', 'o', 'u']
consonants = letters - vowels
result = ""
word_list.each do |word|
if vowels.include?(word[0])
result << word + "ay"
elsif consonants.include?(word[0])
if consonants.include?(word[1])
if consonants.include?(word[2])
result << word[3..-1] + word[0..2] + "ay"
else
result << word[2..-1] + word[0..1] + "ay"
end
else
result << word[1..-1] + word[0] + "ay"
end
else
result << word
end
result << " " unless word == word_list.last
end
return result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment