sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Global Hash in module (solution without $ ) ?

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 188 Views 3 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.
    • jolranJ Offline
      jolran
      last edited by

      Hi.

      During some googeling(think it was St.overflow) I found this solution for making an hash that has constant scope
      in module. Which permits to pass the hash through classes in a module without the use of globals$.
      It's appears to work pretty fine, but I then wonder if it is an acceptable method for working with Sketchup?
      I.e doesent polute the plugin directory or can create havoc for other plugins.
      (it would be unfortunate to trust a solution and then find out it's a big NoNo, later on..)

      Maybe some of you guys have similar stuff implemented already..

      Here's a snippet variant of what I'm using.

      
      module My_stuff
      module DOSTUFF
      
      #initialize Constants..
      
      class Container   
          attr_accessor ;objstorage
          def initialize  
              @objstorage = {}  
          end  
      end 
      
      OBJECTLIST = Container.new #new Hash with global scope in module.  
      
      # Add something to Hash..
      OBJECTLIST.objstorage[;key] = "Somevalue" 
       
      # Additional code goes here......
      
      class Myclass
      	
          def initialize()
              @something = OBJECTLIST.objstorage[;key]
          end
      	
         #Add stuff....
         
      end #class  
         
      end #DOSTUFF
      end #My_stuff
      
      1 Reply Last reply Reply Quote 0
      • A Offline
        Aerilius
        last edited by

        I don't see the difference yet from

        OBJECTLIST = {}
        

        Can you elaborate?

        1 Reply Last reply Reply Quote 0
        • jolranJ Offline
          jolran
          last edited by

          Hah, neither do I 😄

          Your solution is better, I knew some of you foxes had a simpler solution.

          Can't remember what the fuzz was bout creating a whole class for a Hash..
          Maybe for some mixin purposes ? (which I do not need)
          In any case I'd stick to your method.

          Thanks

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            Or something like ?

            ###Usage;### AAA;;XXX.new()
            module AAA
            @@h={}
            @@h['xxx']='zzz'
            	class XXX
            		include AAA
            		@@h['yyy']='aaa'
            		def initialize()
            			@@h['zzz']='ccc'
            			@@h.sort.each{|h|puts "#{h[0]}=#{h[1]}"}
            		end
            	end
            end
            

            TIG

            1 Reply Last reply Reply Quote 0
            • jolranJ Offline
              jolran
              last edited by

              Thanks TIG.

              Your variant is probably more than I need for the moment, but still very clever.

              And I presume (since nobody mentioned it already) quite safe to use ?

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement