Created
May 5, 2014 16:56
-
-
Save jsborjesson/523e2cf8abcc66797fc0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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