#I dont want to define a nother class method exactly the same as the
already declared instance method.
Since file_exists? is an instance method, it is very likely to return
true/false based on the state of the instance (see below). Calling
file_exists in self.method does not make sense unless its
responsibility is to act on an instance of your class - like a
factory, or processing an instance passed to it as a parameter.
# do something on that object
object = SomeClass.new(*args)
return object if object.file_exists?
#there are instance methods depending on this one
Umm, is the file name hard coded, or does it depend on the state of
the instance, like:
If it is hard coded, or depends on a constant, you might as well
define a class method:
CONFIG = “~/.foo.rc”
raise “Config file not found” unless SomeClass.config_exists?
How do you deal with this kind of thing?
Depends on the context.