Ruby signals

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:

thanks in advance.

···

--
Posted via http://www.ruby-forum.com/.

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

HTH
Robert

···

On Mon, Apr 21, 2008 at 12:49 PM, Martin Vales <martin@opengeomap.org> wrote:
--
http://ruby-smalltalk.blogspot.com/

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

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

···

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-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

Kind regards

  robert

thanks robert.

It´s perfect for me this solution

···

--
Posted via http://www.ruby-forum.com/.