Skip to content

Instantly share code, notes, and snippets.

@scottmascio2115
Last active December 21, 2015 19:29
Show Gist options
  • Save scottmascio2115/44ff65d16597b1c50753 to your computer and use it in GitHub Desktop.
Save scottmascio2115/44ff65d16597b1c50753 to your computer and use it in GitHub Desktop.
Solution for Pig-latin
def pig_latin
puts "Please list a word to covert to pig-latin"
word = gets.chomp
vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
first_char = word.chr
vowels.each do |vowels|
if vowels.include?(first_char)
return word
end
end
index_of_vowel = word.index(/[aeiouAEIOU]/)
take_constant_off = word.slice!(0,index_of_vowel)
pig_latin_word = word + take_constant_off + "ay"
pig_latin_word
end
p pig_latin
def pig_latin_no_prompt(word)
vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
first_char = word.chr
vowels.each do |vowels|
if vowels.include?(first_char)
return word
end
end
index_of_vowel = word.index(/[aeiouAEIOU]/)
take_constant_off = word.slice!(0,index_of_vowel)
pig_latin_word = word + take_constant_off + "ay"
pig_latin_word
end
def pig_latin_sentence
puts "Please write a sentence to be converted into pig latin"
sentence = gets.chomp
sentence_array = sentence.split(" ")
sentence_array.map! do |word|
pig_latin_no_prompt(word)
end
sentence_array.join(" ")
end
p pig_latin_sentence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment