From: dblack@... Date: 2003-09-17T03:15:38+09:00 Subject: Re: scrambler one-liner Hi -- On Tue, 16 Sep 2003, Xavier Noria wrote: > I just came across this interesting article at Slashdot that explains that > according to some English university the order of letters in words are not > really relevant for reading as long as the first and the last are at the > right place. (It seems that do not hold in Spanish). > > There is a link to a Perl filter[*] that munges a given text that way and I > wanted to write a mock-up as a one-liner, but in Ruby this time. This is > what I have for now: > > -pe 'gsub!(/\w+/){|w|r=1..w.size-1;w[r]=w[r].split(//).sort_by{rand}.to_s;w}' > > The cool Array.sort_by { rand } trick is a shuffle I saw in Freenode#ruby-lang > last week, I would like very much to remember the nick of who showed it but I > can't remember. > > It seems one-liners are not at the heart of the Ruby community, but hey, > that's funny in the end. Can you shorten it? A little: gsub!(/\w+/){|w|w[1..-2]&&=w[1..-2].split(//).sort_by{rand}.join;w} (Yay! A use for &&=! :-) David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav