• Login
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 193 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.
  • J Offline
    jolran
    last edited by 16 May 2013, 18:35

    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 16 May 2013, 22:03

      I don't see the difference yet from

      OBJECTLIST = {}
      

      Can you elaborate?

      1 Reply Last reply Reply Quote 0
      • J Offline
        jolran
        last edited by 17 May 2013, 06:31

        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
        • T Offline
          TIG Moderator
          last edited by 17 May 2013, 08:42

          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
          • J Offline
            jolran
            last edited by 17 May 2013, 12:36

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

            Advertisement