Callbacks in Ruby?

For general discussion related FlowStone
Exo
Posts: 426
Joined: Wed Aug 04, 2010 8:58 pm
Location: UK
Contact:

Callbacks in Ruby?

Post by Exo »

I would like to implement a callback system in Ruby.

Here is a simple example of what I mean...
Callback.fsm
(1.15 KiB) Downloaded 998 times


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?
Flowstone Guru. Blog and download site for Flowstone.
Best VST Plugins. Initial Audio.
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Callbacks in Ruby?

Post by KG_is_back »

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:

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



RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: Callbacks in Ruby?

Post by RJHollins »

alright .... you Guys are amazing :shock: 8-)

Even if I don't understand the how or why ... it's still is fascinating to try and follow new techniques.

Thanks !!
8-)
Exo
Posts: 426
Joined: Wed Aug 04, 2010 8:58 pm
Location: UK
Contact:

Re: Callbacks in Ruby?

Post by Exo »

Ah yes thanks KG. I had a brain freeze, should have realised output was part of RubyEdit.

Thanks.
Flowstone Guru. Blog and download site for Flowstone.
Best VST Plugins. Initial Audio.
Tronic
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: Callbacks in Ruby?

Post by Tronic »

why not just use the #send __send__ methods?
Exo
Posts: 426
Joined: Wed Aug 04, 2010 8:58 pm
Location: UK
Contact:

Re: Callbacks in Ruby?

Post by Exo »

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.
Flowstone Guru. Blog and download site for Flowstone.
Best VST Plugins. Initial Audio.
Tronic
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: Callbacks in Ruby?

Post by Tronic »

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.

Callback_(Tronic).fsm
(1.16 KiB) Downloaded 977 times
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: Callbacks in Ruby?

Post by MyCo »

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.
Tronic
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: Callbacks in Ruby?

Post by Tronic »

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.
Tronic
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: Callbacks in Ruby?

Post by Tronic »

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.
Post Reply