Last active
August 29, 2015 14:08
-
-
Save wengkhing/b945179548a53c1287f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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