Sorry that I have no clue how to title this, I'm having a hard time looking this up because I don't know how to say this. Anyway...
Let's say I have a class that looks like this for example:
class Run
def self.starting
print "starting..."
end
def self.finished
print "Finished!"
end
end
All of the methods in Run
have self
before them, meaning that I don't have to do run = Run.new
and I can just do Run.starting
. Now let's say that I wanted to add some instance variables...
class Run
attr_accessor :starting, :finished
def self.starting
print "starting..."
@starting = true
@finished = false
end
def self.finished
print "finished!"
@starting = false
@finished = true
end
end
What if I wanted to access those instance variables from outside the class? I know that something like print "#{Run.finished}"
or print "#{Run.starting}"
won't do anything. Can I do that without run = Run.new
? Or should I just remove self
and then use run = Run.new
? (Sorry if this question is a mess.)