Created
December 3, 2013 19:08
-
-
Save sdanko11/7775575 to your computer and use it in GitHub Desktop.
Pig Latin Translation
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
| class PigLatinTranslation | |
| attr_reader :phrase | |
| def initialize(phrase) | |
| @phrase = phrase | |
| @words_in_phrase = [] | |
| end | |
| def translate | |
| starts_with_vowel? | |
| end | |
| def words | |
| @words_in_phrase = @phrase.split(' ') | |
| end | |
| private | |
| def starts_with_vowel? | |
| @words_in_phrase.each do |word| | |
| if word.start_with?('a','e','i','o','u') | |
| print "#{word}way " | |
| else | |
| first_letter = word[0] | |
| word.slice!(0) | |
| print "#{word}#{first_letter.downcase}ay " | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment