Skip to content

Instantly share code, notes, and snippets.

@jsborjesson
Created May 5, 2014 16:56
Show Gist options
  • Select an option

  • Save jsborjesson/523e2cf8abcc66797fc0 to your computer and use it in GitHub Desktop.

Select an option

Save jsborjesson/523e2cf8abcc66797fc0 to your computer and use it in GitHub Desktop.
module Typoglycemia
def self.convert(text)
text.gsub(/(\w+)/) { |word| scramble_middle_characters(word) }
end
def self.scramble_middle_characters(word)
return word if word.length < 4
word[0] + shuffle_letters(word[1...-1]) + word[-1]
end
def self.shuffle_letters(text)
text.chars.shuffle.join
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment