Skip to content

Instantly share code, notes, and snippets.

@durrellchamorro
Created December 11, 2015 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save durrellchamorro/7db75f22425ef12caee0 to your computer and use it in GitHub Desktop.
Save durrellchamorro/7db75f22425ef12caee0 to your computer and use it in GitHub Desktop.
Pig Latin
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