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
Callbacks in Ruby?
Callbacks in Ruby?
I would like to implement a callback system in Ruby.
Here is a simple example of what I mean...
This doesn't work because the output method is not recognized within the class.
The benefits of this should be obvious we could send data from anywhere in the schematic to anywhere else, like sending data from low down in the hierarchy back to the top (which is what I intend to do)
So is there a way to get this to work?
Here is a simple example of what I mean...
This doesn't work because the output method is not recognized within the class.
The benefits of this should be obvious we could send data from anywhere in the schematic to anywhere else, like sending data from low down in the hierarchy back to the top (which is what I intend to do)
So is there a way to get this to work?
-
KG_is_back
- Posts: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: Callbacks in Ruby?
I believe the problem is, that "output" is a function of RubyEdit class. And the Callback class you've created doesn't inherit from RubyEdit, which means "output" is not declared for it.
In order for it to work, you have to send it the module it resides in when initialized... look at this fix:
In order for it to work, you have to send it the module it resides in when initialized... look at this fix:
Code: Select all
class Callback
def initialize(mod)
@module=mod
end
def doSomething()
@module.output "go" , nil
end
end
@call = Callback.new(self)
output "callback", @call
Re: Callbacks in Ruby?
alright .... you Guys are amazing
Even if I don't understand the how or why ... it's still is fascinating to try and follow new techniques.
Thanks !!

Even if I don't understand the how or why ... it's still is fascinating to try and follow new techniques.
Thanks !!
Re: Callbacks in Ruby?
Ah yes thanks KG. I had a brain freeze, should have realised output was part of RubyEdit.
Thanks.
Thanks.
Re: Callbacks in Ruby?
why not just use the #send __send__ methods?
Re: Callbacks in Ruby?
I wasn't aware of these methods. Can you give an example?
I'm not well versed in Ruby so I tend to default to doing things the 'Java' way.
I'm not well versed in Ruby so I tend to default to doing things the 'Java' way.
Re: Callbacks in Ruby?
This is an example of __send__ method
I used the $intern_this gloabal variable to get the local instance of RubyEdit Class
to inherit it's intenal declared methods.
I used the $intern_this gloabal variable to get the local instance of RubyEdit Class
to inherit it's intenal declared methods.
Re: Callbacks in Ruby?
Tronic wrote:I used the $intern_this gloabal variable to get the local instance of RubyEdit Class
to inherit it's intenal declared methods.
This doesn't work, because $intern_this seems to point to the last edited Ruby-Edit, not to the class that contains the code.
Re: Callbacks in Ruby?
yes you're right, but I think it's a problem of FS, for as the module is initialized,
but if you retrig the class it works correctly.
the $intern_this, it seems to me, point to the current RubyEdit module.
Edit: work only for the last call of Callback class, so Myco you you're right.
but if you retrig the class it works correctly.
the $intern_this, it seems to me, point to the current RubyEdit module.
Edit: work only for the last call of Callback class, so Myco you you're right.
Re: Callbacks in Ruby?
However my example of callback with the method __send__ works well,
the only problem is if you want to inherit the methods of class RubyEdit.
the only problem is if you want to inherit the methods of class RubyEdit.