sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🚨 Skimp | 25% Off until March 30 Buy Now

    Access module variables from inside a module class

    Scheduled Pinned Locked Moved Developers' Forum
    2 Posts 2 Posters 389 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      sepultribe
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        "Programming Ruby - The Pragmatic Programmer's Guide" explains it all.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0

        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 Login
        • 1 / 1
        • First post
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement