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?
47 posts
• Page 1 of 5 • 1, 2, 3, 4, 5
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?
- Exo
- Posts: 426
- Joined: Wed Aug 04, 2010 8:58 pm
- Location: UK
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
- KG_is_back
- Posts: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
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 !!
- RJHollins
- Posts: 1571
- Joined: Thu Mar 08, 2012 7:58 pm
Re: Callbacks in Ruby?
Ah yes thanks KG. I had a brain freeze, should have realised output was part of RubyEdit.
Thanks.
Thanks.
- Exo
- Posts: 426
- Joined: Wed Aug 04, 2010 8:58 pm
- Location: UK
Re: Callbacks in Ruby?
why not just use the #send __send__ methods?
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
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.
- Exo
- Posts: 426
- Joined: Wed Aug 04, 2010 8:58 pm
- Location: UK
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.
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
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.
-
MyCo - Posts: 718
- Joined: Tue Jul 13, 2010 12:33 pm
- Location: Germany
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.
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
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.
- Tronic
- Posts: 539
- Joined: Wed Dec 21, 2011 12:59 pm
47 posts
• Page 1 of 5 • 1, 2, 3, 4, 5
Who is online
Users browsing this forum: No registered users and 53 guests