Last active
December 30, 2015 09:19
-
-
Save vanmichael/7808366 to your computer and use it in GitHub Desktop.
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
require 'pry' | |
class PigLatinTranslation | |
def initialize(phrase) | |
@phrase = phrase.downcase | |
end | |
#provide the pig latin translation | |
def translate | |
@words = words | |
@words.each do |word| | |
if starts_with_vowel?(word) | |
word << ("ay") | |
else | |
until starts_with_vowel?(word) | |
word << ("#{word[0,1]}") | |
word[0,1]="" | |
end | |
word << "ay" | |
end | |
end | |
@words.join(" ") | |
end | |
private | |
#an array of words in the phrase | |
def words | |
@phrase.split(" ") | |
end | |
def starts_with_vowel?(word) | |
["a","e","i","o","u"].include?word[0,1] | |
end | |
end | |
x = PigLatinTranslation.new('Hello Van') | |
puts x.translate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment