|
FileTest module confusion: msg#01228lang.ruby.general
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.
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: win32ole and excel, MikkelFJ |
|---|---|
| Next by Date: | Re: [OT] Programming practice question, MikkelFJ |
| Previous by Thread: | Glade Shortcut Keys, Tom Sawyer |
| Next by Thread: | Re: FileTest module confusion, Jim Freeze |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |