Joel VanderWerf
2/1/2006 10:43:00 PM
Neowulf wrote:
> 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
>
Or
fu = FileUtils
(without the .new)
I don't think FileUtils.mv creates a new instance of FileUtils. These
are class methods, so you can call them directly on the class object
without instantiating the class.
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407