Note that the forums is not usually the place for “completed code”.
(I myself have posted a smattering of complete code examples here, but intend to move them to GitHub gists or full code repositories.)
I did post a complete example Instance Drag Tool here …
Draw model while moving mouse in custom tool - #11 by DanRathbun
Please learn Ruby best practices for a shared environment. ( ...click to expand... )
Regarding your “test” code. Please learn Ruby best practices for a shared environment.
No global variables.
A unique namespace module wrapping everything (but even a name like “Testing” for namespace sake is fine for posting snippets.)
A namespace module is important because it is a no-no to define classes at the top level for your own use. (Only Ruby Core and API classes that everyone will use should be defined in the top level ObjectSpace.)
Within your top level namespace module is where you define extension submodules. This is important because each extension’s code needs to be separated from each other so that they do not interfere.
Define custom classes inside extension submodules where they will be used.
When coding use good practice so that when you need help others are able to understand what your code is trying to do:
-
Comment your classes and methods with at least a simple description. This lets other readers know what a class or method is intended to do. And later when you yourself come back to the code months later, these comments will help you remember how things work.
-
Insert comments in between code statements when more explanation is needed.
-
Use descriptive reference (variable) names, except for the simplest iterator index variables in loops.
-
Use proper 2 space indentation. (Set your code editor to replace tabs with spaces so that when you need to post code snippets the forum can display the code correctly.)
~