Skip to content

Instantly share code, notes, and snippets.

@jdenen
Created December 6, 2016 18:04
Show Gist options
  • Save jdenen/820103748b69fe664bd1f1cd58794bb9 to your computer and use it in GitHub Desktop.
Save jdenen/820103748b69fe664bd1f1cd58794bb9 to your computer and use it in GitHub Desktop.
VOWELS = ['a', 'e', 'i', 'o', 'u']
word = gets.chomp.chars.map(&:downcase)
def modify_vowel(char)
VOWELS.include?(@previous_char) ? char : "idig#{char}"
end
def is_vowel?(char)
VOWELS.include?(char)
end
def replace_eligible_vowel(char)
is_vowel?(char) ? modify_vowel(char) : char
end
gibberish = word.each_with_object([]).with_index do |(char, new_word), index|
@previous_char = word[index - 1] unless index.zero?
new_word << replace_eligible_vowel(char)
end
puts gibberish.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment