If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
[Ruby] Simplest access to a class instance?
2 posts
• Page 1 of 1
[Ruby] Simplest access to a class instance?
Scenario:
3 RubyEdits connected to views, each view displays a part of a whole. There's one class that manages everything, defined and instantiated in the first of the 3 modules.
First Implementation:
I used a class variable for accessing the class instance from all 3 RubyEdits. Works like a charm. However, let me remind you that all instances of a plugin share the same Ruby Interpreter. Therefore, if working with several instances of this schematic, any instance overwrites the class for all other instances as well.
Question:
I tried to use class instance variables instead and send the class instance out via RubyValue. Unfortunately that creates copies of the class instance, instead of letting me access the instance itself. How can I have access to one class instance from all 3 modules, while still have individual class instances per plugin instance? Do I really need to implement a callback system?
3 RubyEdits connected to views, each view displays a part of a whole. There's one class that manages everything, defined and instantiated in the first of the 3 modules.
First Implementation:
I used a class variable for accessing the class instance from all 3 RubyEdits. Works like a charm. However, let me remind you that all instances of a plugin share the same Ruby Interpreter. Therefore, if working with several instances of this schematic, any instance overwrites the class for all other instances as well.
Question:
I tried to use class instance variables instead and send the class instance out via RubyValue. Unfortunately that creates copies of the class instance, instead of letting me access the instance itself. How can I have access to one class instance from all 3 modules, while still have individual class instances per plugin instance? Do I really need to implement a callback system?
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: [Ruby] Simplest access to a class instance?
You can create your class as a module. Then create Anonymous class in each plugin and include the module in it. Then send reference to your anonymous class to each ruby-edit in that plugin during startup. This would ensure that each plugin has its own instance of that class.
https://www.mobomo.com/2012/2/using-anonymous-classes-and-modules-in-ruby/
https://www.mobomo.com/2012/2/using-anonymous-classes-and-modules-in-ruby/
- KG_is_back
- Posts: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
2 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 71 guests