Skip to content

Instantly share code, notes, and snippets.

@phlco
Created April 3, 2014 13:03
Show Gist options
  • Select an option

  • Save phlco/9953890 to your computer and use it in GitHub Desktop.

Select an option

Save phlco/9953890 to your computer and use it in GitHub Desktop.
Igpay Atinlay

Morning Exercise

Pig Latin Translater

Implement a Ruby class called Translater with a class method called to_pig that takes a word (string) as an argument and returns its pig latin equivalent. Description of the rules from Wikipedia:

For words that begin with consonant sounds, the initial consonant or consonant cluster is moved to the end of the word, and "ay" is added, as in the following examples:

Step 1

Write rspec tests to check the following outputs

  • "happy" → "appyhay"
  • "duck" → "uckday"
  • "glove" → "oveglay"

For words that begin with vowel sounds or silent letter, "way" is added at the end of the word. Examples are

  • "egg" → "eggway"
  • "inbox" → "inboxway"
  • "eight" → "eightway"

The letter 'y' can play the role of either consonant or vowel, depending on its location

  • "yellow" → "ellowyay"
  • "rhythm" → "ythmrhay"

How do you deal with words starting with "qu" or "squ" ?

  • "queen" → "eenquay"
  • "squeal" → "ealsquay"

Step 2

Make them pass with some sweet code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment