Created
December 11, 2015 22:27
-
-
Save durrellchamorro/7db75f22425ef12caee0 to your computer and use it in GitHub Desktop.
Pig Latin
This file contains 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
class PigLatin | |
def self.translate(string) | |
string.split(' ').map do |word| | |
if /yt|xr/ =~ word[0..1] | |
word << 'ay' | |
elsif /ye/ =~ word[0..1] | |
word.chars.rotate.join << 'ay' | |
elsif /thr|sch/ =~ word[0..2] | |
word.chars.rotate(3).join << 'ay' | |
elsif /ch|qu|th/ =~ word[0..1] | |
word.chars.rotate(2).join << 'ay' | |
elsif /ch|qu/ =~ word[0..2] | |
word.chars.rotate(3).join << 'ay' | |
elsif %w(a e i o u).include? word[0] | |
word << 'ay' | |
else | |
word.chars.rotate.join << 'ay' | |
end | |
end.join(' ') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment