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.
···
On Wed, Jul 13, 2011 at 3:55 PM, Simon Harrison <simon@simonharrison.net>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?
Ah right, cheers Josh. I wasn't sure if he meant syntactic sugar for
sprintf.
Robert: I didn't mean the colon.
I didn't assume you did.
Ryan's post ended abruptly on rubyforum
with
"which is just syntactic sugar for:"
and nothing else. Anyway it doesn't matter. Cheers.
Interestingly the quote is shown in full in the mailing list. I read
his posting on the mailing list and didn't even notice the line was
gone in ruby-forum. Apparently the gateway needs some fixing...
Kind regards
robert
···
On Fri, Jul 15, 2011 at 8:52 PM, Simon Harrison <simon@simonharrison.net> wrote:
I think Ryan was saying that `receiver % arg` was syntactic sugar for
`receiver.%(arg)` but the second part was in a quote which made it look like
it wasn't part of his response, so his response looked unfinished.
···
On Fri, Jul 15, 2011 at 10:34 AM, Robert Klemme <shortcutter@googlemail.com>wrote:
On Thu, Jul 14, 2011 at 8:55 PM, Simon Harrison <simon@simonharrison.net> > wrote:
> Ryan Davis wrote in post #1010583:
>> On Jul 13, 2011, at 14:51 , Simon Harrison wrote:
>>
>>
>> What you really want to execute is:
>>
>>> (1..100).each do |num|
>>> FileUtils.mkdir "Prefix-%03d" % num
>>> end
>>
>> which is just syntactic sugar for:
>
> Thanks for clearing that up, Ryan. Out of curiosity what was the end of
> the last line above?