Skip to content

Instantly share code, notes, and snippets.

@vanmichael
Last active December 30, 2015 09:19
Show Gist options
  • Save vanmichael/7808366 to your computer and use it in GitHub Desktop.
Save vanmichael/7808366 to your computer and use it in GitHub Desktop.
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