From: Robert Klemme Date: 2008-04-22T15:40:03+09:00 Subject: Re: ruby signals On 21.04.2008 13:09, Robert Dober wrote: > On Mon, Apr 21, 2008 at 12:49 PM, Martin Vales 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-forum.com/. >> >> > > 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/Observable.html Kind regards robert