Skip to content

Instantly share code, notes, and snippets.

@wengkhing
Last active August 29, 2015 14:08
Show Gist options
  • Save wengkhing/b945179548a53c1287f4 to your computer and use it in GitHub Desktop.
Save wengkhing/b945179548a53c1287f4 to your computer and use it in GitHub Desktop.
def to_pig_latin(word)
word.sub(/([^aeiou]+)([aeiou]*\S*)/, "\\2\\1ay")
end
def to_pig_latin_sentence(sentence)
words = sentence.split(" ")
count = 0
words.map! do |word|
count += 1 unless to_pig_latin(word) == word
to_pig_latin(word)
end
puts "Converted #{count} word(s)."
words.join(" ")
end
while true
print "Insert sentence: "
sentence = gets.chomp
break if sentence.empty?
puts to_pig_latin_sentence(sentence)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment