Newbie query regarding ruby best practice



Hi all,

I've just finished working on a few util scripts in Ruby to cut my
teeth and I was wondering what the best practice is with regards the
use of class methods.

E.g. Is it better to do something like this...

require 'fileutils'

FileUtils.mv(myfile,newpath)
FileUtils.cp(newpath,anotherpath)
FileUtils.rm(newpath)

or this...

fu = FileUtils.new

fu.mv(myfile,newpath)
fu.cp(newpath,anotherpath)
fu.rm(newpath)

I assume the second would only create a single instance of a
"fileutils" object, thus requiring less overhead than the first?

~Neowulf

.



Relevant Pages

  • Re: Ruby - Newbie to Guru - Advice?
    ... I've read lots of documentation and articles, ... What programming exercises would you want to help you practice new ... Ruby things as you learn them? ... How would keep track of your progress to know you were progressing? ...
    (comp.lang.ruby)
  • Re: Polymorphic block parameters -- an idea for Ruby 2.0
    ... has occured to me before with regards to default values (becuase blocks ... Ruby is working against itself here. ... def foo(&b) ...
    (comp.lang.ruby)
  • Re: Title entry function problem
    ... compile their own version of Ruby, ... it takes less than a minute to install ... it does not have rails inbuilt, so after installing run from console ...
    (comp.lang.ruby)
  • Re: free motion stippling question
    ... However, do them with a specific purpose: you need to find out which direction you find that you prefer to move the quilt in. ... You will learn a lot of valuable 'stuff' by doing practice pieces - not just basically how to do it>g< ... You might find your own style, that you can do much better than the generally seen stippling. ... Best regards, ...
    (rec.crafts.textiles.quilting)
  • Re: Memorizing - Optimum number of pieces?
    ... >> Rudi Menter wrote: ... So you mean that to practice means to include ... >>> Regards! ... Thanks John, ...
    (rec.music.classical.guitar)