Marcel Molina Jr.
7/9/2006 6:16:00 PM
On Mon, Jul 10, 2006 at 01:05:06AM +0900, Bil Kleb wrote:
> dblack@wobblini.net wrote:
> >
> > Dir.chdir("photos") do
> > files = Dir["*"]
> > new_names = [*0...files.size].sort_by { rand }
> > files.zip(new_names).each do |f,n|
> > File.rename(f, n.to_s)
> > end
> > end
>
> Thanks David.
>
> I'll push that over and see what comes back.
>
> Also, thanks for showing "zip" in action -- I just
> learned about that one a couple months ago and hadn't
> figured out a place to use it yet.
One useful use of zip is transformation two arrays into hash pairs:
> Hash[*%w(a b c d).zip([1, 2, 3, 4]).flatten]
=> {"a"=>1, "b"=>2, "c"=>3, "d"=>4}
marcel
--
Marcel Molina Jr. <marcel@vernix.org>