SketchUp Extension Template
Multi-File, Multi-Class with SharedConstants Mixin Module
Warning! This coding pattern is not allowed in Ruby 3 (SketchUp 24+)
Class and Module @@ variables can no longer be shared across class or module scopes.
Myself, I do not like this change as it removes the power of @@ variables. But apparently too many coders did not understand how to use them, so the Ruby Core project basically “dumbed them down”.
In Ruby versions previous to 3, we could have multiple classes and modules sharing @@ variables by inclusion from a mixin module. Any of the sharing classes or modules could make changes to the shared variables. In Ruby 3, instead a warning is generated and a unique @@ variable will be created in the mixee class or module, thereby defeating the shareability.
Going forward, we will need to define an object (a module or a class instance) that holds the variables and data to be shared, and the various other modules and classes would access the variables and data via singleton or instance methods calls upon the shared object.
MultiClass_MultiFile.zip (3.9 KB) - UPDATED 2024-05-10
Change module name “Author” in the template files to your own unique top-level company name, brand name, initials, or online nickname. (Do not use some other entity’s trademarks, salesmarks, brandnames, patented names, etc. Ie, do not use “Sketchup” or “Layout” in any form, in any case combination, with or without appended or prepended words.)
Change the “MultiClassPlugin” sub-module name (in all files,) to the name of your particular plugin.
Save your template as encoding UTF-8 without BOM (Bit Order Mark.)
It is also recommend that Unix type end of lines be used. (Although some prefer Windows EOLs on PC because snippets can be pasted into the Ruby Console and line breaks work. Snippets with Unix EOLs will not line break in the PC console. I personally have only the little snippet files in my “Snippets” folder set to Windows EOLs.)