ruby signals

R

Robert Dober

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.

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
 
R

Robert Klemme

I have no idea what Gnome really needs but the doc is pretty good IIRC.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,291
Messages
2,571,455
Members
48,132
Latest member
KatlynC08

Latest Threads

Top