[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ruby signals

Martin Vales

4/21/2008 10:50:00 AM


Someone know like connect a signal inside a class??
I am working in ruby gnome, but i thinkl this is a ruby generic
question.

class One
def initialize(callback)
callback
end

end

class Main
def initialize
One.new("talk_with_me")
end

def talk_with_me
puts "i am here"
end

end


Here we can see a php5 doing the same:
http://phpexperts.blogspot.com/2007/05/splash-screens-with-ph...

thanks in advance.
--
Posted via http://www.ruby-....

3 Answers

Robert Dober

4/21/2008 11:10:00 AM

0

On Mon, Apr 21, 2008 at 12:49 PM, Martin Vales <martin@opengeomap.org> wrote:
>
> Someone know like connect a signal inside a class??
> I am working in ruby gnome, but i thinkl this is a ruby generic
> question.
>
I have no idea what Gnome really needs but the doc is pretty good IIRC.
> class One
> def initialize(callback)
> callback
> end
>
> end
>
> class Main
> def initialize
> One.new("talk_with_me")
> end
>
> def talk_with_me
> puts "i am here"
> end
>
> end
>
>
>
> thanks in advance.
> --
> Posted via http://www.ruby-....
>
>

You could do different things, e.g. call a proc or instance_eval a
block, as I suspect that you need information of the class I would
rather instance_eval.

class Two
def initialize &blk
instance_eval &blk
end
def say_hello; puts "hello" end
end

Two.new do say_hello end

HTH
Robert
--
http://ruby-smalltalk.blo...

---
Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

Robert Klemme

4/22/2008 6:37:00 AM

0

On 21.04.2008 13:09, Robert Dober wrote:
> On Mon, Apr 21, 2008 at 12:49 PM, Martin Vales <martin@opengeomap.org> wrote:
>> Someone know like connect a signal inside a class??
>> I am working in ruby gnome, but i thinkl this is a ruby generic
>> question.
>>
> I have no idea what Gnome really needs but the doc is pretty good IIRC.
>> class One
>> def initialize(callback)
>> callback
>> end
>>
>> end
>>
>> class Main
>> def initialize
>> One.new("talk_with_me")
>> end
>>
>> def talk_with_me
>> puts "i am here"
>> end
>>
>> end
>>
>>
>>
>> thanks in advance.
>> --
>> Posted via http://www.ruby-....
>>
>>
>
> You could do different things, e.g. call a proc or instance_eval a
> block, as I suspect that you need information of the class I would
> rather instance_eval.
>
> class Two
> def initialize &blk
> instance_eval &blk
> end
> def say_hello; puts "hello" end
> end
>
> Two.new do say_hello end

Here's my - equally Gnome agnostic - suggestion

class Model
def initialize(&callback)
@cb = callback
end

def some_event
@cb.call
end
end

class View
def initialize
@md = Model.new { talk_with_me }
end

def talk_with_me
puts "i am here"
end

end

But also see http://ruby-doc.org/core/classes/Obser...

Kind regards

robert

Martin Vales

4/22/2008 7:04:00 AM

0


>
> Kind regards
>
> robert

thanks robert.


It´s perfect for me this solution
--
Posted via http://www.ruby-....