I’m trying my first major Ruby script (to automate some engineering
calculations I’m performing), and running into some difficulty
understanding what Ruby expects in terms of class and class methods. It
may well be that my background in O-O programming (mostly Fortran 95) is
not helping me adapt to Ruby very well.
I am running Ruby Gems 1.8 (jruby) on the Eclipse IDE.
I currently have one script file, named ExcessLoad.rb. Within this
file, I define a class as:
class << FileClass
— Class method
def openAnalysisFiles
…
end
end
Later in the script, I want to instantiate the class, and invoke the
class method. I’ve tried a number of different ways (the following is
where it is right now):
analysisFiles = FileClass.new # Instantiate the class
analysisFiles.openAnalysisFiles # Attempt to invoke the
method
I keep running into the following exceptions being thrown:
“uninitialized constant FileClass (NameError)”
If I change “class << FileClass” to “class FileClass”, I get this
problem:
“in `openAnalysisFiles’: uninitialized constant FileClass::FILE
(NameError)”
What am I doing wrong?? Generally speaking, what does Ruby expect me to
do to with regards to initializing a class and associated methods? In
Fortran 95 you simply instantiate the class, and the class methods
automatically are available to the object.
Regards, TPL