From: Josh Cheek Date: 2011-07-14T06:15:37+09:00 Subject: Re: Creating a range of directories --20cf3071c73ad4d4ba04a7f9ea40 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jul 13, 2011 at 3:55 PM, Simon Harrison wrote: > I'm wanting to create a range of directories with a prefix, like the > following: > > /prefix-001 > /prefix-002 > > etc. > > The following works, but seems to smell a bit. > > *************************** > > require 'fileutils' > include FileUtils > > var = 1..100 > dirs = var.map { |n| "%03d" % n } > dirs.each { |n| n.insert(0, "Prefix-") } > > mkdir(dirs) > > **************************** > > Any better ways to accomplish this? And, does anyone know of a good > tutorial/book for working with files and directories? > > Cheers > > -- > Posted via http://www.ruby-forum.com/. > > Also in this case, where you use a FileUtils method only once, including it seems to be more overhead than benefit. But if you do prefer inclusion, then in cases like this, where you only ever call its methods from main, I think it is better to extend rather than include. This way you don't pollute Object with all of its methods. --20cf3071c73ad4d4ba04a7f9ea40--