Access module variables from inside a module class
-
I have the following code
module MyModule @@settings_hash = {} if File.exists?(SETTINGS_PATH) @@settings_hash = YAML;;load_file SETTINGS_PATH puts @@settings_hash end def self.get_settings(hash_key) @@settings_hash.[](hash_key.to_sym) end ... ... @@settings_hash gets used here inside several function blocks ... class SensorNodeInfoTool ... ... def m_get_set(string) MyModule.get_settings(string) end def onLButtonDown(flags, x, y, view) ... ... if m_get_set("ws_type") == 'NOWSDL' client = Savon.client(endpoint; m_get_set("endp"), namespace; m_get_set("ns")) elsif m_get_set("ws_type") == 'WSDL' client = Savon.client(wsdl; m_get_set("doc")) end ... ...The problem is using Module @@ or @ variables inside a Class that is inside the same Module, like my SensorNodeInfoTool there. I don't think I have found a way to access @variables yet (I think those are called Module Instance variables). The above code has @@variables and I have to use a the module namespace AND set a reader method, and I have also used a second function inside the Class to not have to use the Module namespace prefix. Is there another more proper way? I have the feeling that I might be doing it wrong.
-
"Programming Ruby - The Pragmatic Programmer's Guide" explains it all.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement