I met strange difficulty developing one project. I dont have enough experience with classes so this is why I ask here. I have one class which is initialized with one parameter and I need other classes to call that class functions but I cant until that class is initialized so I asking how I could do that.
Here is some example what I talking about:
class AVR
def initialize(device)
@device = device
@avr_conf = YAML::load(File.open("./devices/#{device}.yaml"))
end
def avr_conf
return @avr_conf
end
end
class IO
def setMode(a,b)
"#{AVR.avr_conf[a]} = #{b}"
end
end
You either: need an instance, or to make
avr_confa class method (and initialize differently).With an instance:
With a config singleton (roughly):
Then class
IOwould need to use the updated version, however that’s appropriate.If IO isn’t going to/can’t get an instance, the class/singleton-config might make more sense, although that approach always makes me a little nervous.