Created
July 18, 2009 12:57
-
-
Save pcdavid/149548 to your computer and use it in GitHub Desktop.
scrmable.rb
This file contains 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
#!/usr/bin/env ruby | |
class String | |
def scrmable | |
return self if not self =~ /\w/m | |
first, *letters = self.split(//) | |
last = letters.pop | |
if last | |
order = Hash.new | |
letters.each do |l| | |
begin | |
o = rand(2 * letters.length) | |
end while order.has_key?(o) | |
order[o] = l | |
end | |
letters = order.keys.sort.collect { |i| order[i] } | |
return first + letters.join + last | |
else | |
return first | |
end | |
end | |
end | |
ARGF.each do |line| | |
line.split(/([^[:alnum:]]*[\s[:punct:]]+)/).each do |word| | |
print word.scrmable | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment