D
Damphyr
OK, bare with me, this is brainstorming of a sorts:
I want to have some kind of event notification from my classes.
Typically what I would do would be to pass a logger object and let the
class log by itself, but I'm not really satisfied with this solution in
most cases.
What I would prefer was define a callback method and give this to the
object. Then I could do whatever I want with it and not only use logs.
Mostly I want to have progress reports.
something like
class A
def set_callback notify
@notify=notify
end
def something
puts "something"
send(@notify) if @notify
end
end
def coocoo
puts "hey"
end
a=A.new
a.something
a.set_callbackcoocoo)
a.something
Now this does exactly what I want and can be wrapped up in a module to
be included for general use.
Question: Is there a "better" solution? What are my alternatives?
Cheers,
V.-
--
http://www.braveworld.net/riva
____________________________________________________________________
http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
http://www.freemail.gr - free email service for the Greek-speaking.
I want to have some kind of event notification from my classes.
Typically what I would do would be to pass a logger object and let the
class log by itself, but I'm not really satisfied with this solution in
most cases.
What I would prefer was define a callback method and give this to the
object. Then I could do whatever I want with it and not only use logs.
Mostly I want to have progress reports.
something like
class A
def set_callback notify
@notify=notify
end
def something
puts "something"
send(@notify) if @notify
end
end
def coocoo
puts "hey"
end
a=A.new
a.something
a.set_callbackcoocoo)
a.something
Now this does exactly what I want and can be wrapped up in a module to
be included for general use.
Question: Is there a "better" solution? What are my alternatives?
Cheers,
V.-
--
http://www.braveworld.net/riva
____________________________________________________________________
http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
http://www.freemail.gr - free email service for the Greek-speaking.