Some modules are meant for mixing in, some aren't.  FileTest isn't.
Some modules that aren't designed for mixing in can still be useful when mixed
in, others can't.  FileTest can't.

I might be wrong :)

Anyway, to test the existence of a file, choose your weapon:
  FileTest.exists?(path)
  File.stat(path).exists?
  test ?e, path

Cheers,
Gavin


----- Original Message -----
From: "James Toomey" <jamesvtoomey / yahoo.com>
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <ruby-talk / ruby-lang.org>
Sent: Wednesday, August 14, 2002 3:50 AM
Subject: FileTest module confusion


> I'm just learning Ruby, so please forgive any naivete revealed here.
> In the following code,
> #---------------------------------------
> class DummyClass
>   include FileTest
> end
> DummyInstance = DummyClass.new
> #This works
> puts FileTest.exists?("c:\\autoexec.bat")
> #This doesn't work
> puts DummyInstance.exists?("c:\\autoexec.bat")
> #---------------------------------------
> it seems like the FileTest module acts more like a class than a
> module. From what I've read, modules can be used as "mixins" to
> enhance existing classes but cannot be instantiated on their own.
> However, the opposite seems to be occurring.
> If I substitute the FileTest module for my own module, the expected
> behavior occurs:
> #---------------------------------------
> module SampleModule
>  def displayMessage
>   return "Hello World!"
>  end
> end
> class DummyClass2
>   include SampleModule
> end
> DummyInstance2 = DummyClass2.new
> #This works
> puts DummyInstance2.displayMessage
> #This doesn't work
> puts SampleModule.displayMessage
> #---------------------------------------
> Am I using the FileTest module incorrectly? And if FileTest can be
> used as a standalone object (instead of being mixed in), why isn't it
> a class instead of a module? I know there's the File::Stat object, but
> it seems to operate a bit differently than FileTest.