Skip to content

Instantly share code, notes, and snippets.

@scarow
Created August 7, 2013 03:48
Show Gist options
  • Save scarow/6171042 to your computer and use it in GitHub Desktop.
Save scarow/6171042 to your computer and use it in GitHub Desktop.
Pig latin keeping punctuation
def pig_latin word
results_array = Array.new
counter = 0
vowels = ["a","e","i","o","u"]
if word.downcase[0] != ("a" || "e" || "i" || "o" || "u")
split_word = word.split(//)
split_word.each do |current_letter|
if vowels.include?(current_letter)
break
else
counter += 1
end
end
else
return word + "ay"
end
split_word.rotate(counter).join() + "ay"
end
def pig_latin_sentence
p "Type your sentence"
sentence = gets.chomp
punctuation = sentence.scan(/\W/)
words = sentence.split(/\W/)
p punctuation
p words
answer = words.map! do |x|
p pig_latin x
end
p answer.zip(punctuation).join("").downcase.capitalize
end
pig_latin_sentence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment