From: Aviv Nitsan <avnit7@gmail.com>
Date: April 21, 2006 2:40:25 PM CDT
To: submission@rubyquiz.com
Subject: Please Forward: Ruby Quiz SubmissionSubmission for Ruby Quiz #76 (Text Munger):
#!/usr/bin/ruby
class Array
def scramble
a = self.dup
a2 =
a.length.times do
a2.push(a.slice!(rand(a.length)))
end
a2
end
endclass String
def scramble_middle
self.gsub(/(\w+)/) do |word|
if word.length > 2
word.gsub(/(#{word[1..-2]})/) {$1.split(//).scramble.join('')}
else
word
end
end
end
endtext = STDIN.gets
puts text.scramble_middle
···
Begin forwarded message: