Method: String#munge
- Defined in:
- lib/extra/string.rb
#munge ⇒ Object
My unsubmitted answer to a previous RubyQuiz question. Basically #munge will take words, scramble only the middle contents of the word while the first and last letters remain intact.
Example: 'You look like a terrifying goblin'.munge #=> "You look lkie a tiifyenrrg goilbn"
Returns: Munged string
93 94 95 96 97 98 99 100 101 |
# File 'lib/extra/string.rb', line 93 def munge gsub(/\w+/u) do |word| if word.size > 2 word[0,1] + word[1...-1].shuffle + word[-1,1] else word end end end |