Application design advice

I'm using the Eventmachine framework and being fairly new to ruby am
wondering about the best way to structure my code. Being an event
based framework there is a lot of jumping around in the code from one
callback to another.

In particular, most of the methods that I call to set callbacks take a
block. The code I want to run is usually going to be a method within
a class. For instance:

c = Transaction.new
ProtocolHandler.setcallback {|args| c.Process)

This seems to be the easiest way to get the callback to run my method
and pass it the arguments I need. Is there a better way to do this or
am I on the right track?

c = Transaction.new
ProtocolHandler.setcallback {|args| c.Process)

Oops, that should be..

ProtocolHandler.setcallback {|args| c.Process(args)}

Which brings up another question. How would I write a similar block
to handle multiple arguments where the number of arguments isn't known
when I call setcallback?

snacktime wrote:

c = Transaction.new
ProtocolHandler.setcallback {|args| c.Process)

Just a question: why is #Process capitalized?

Cheers,
Daniel

ProtocolHandler.setcallback {|*args| c.Process(*args)}

-a

···

On Thu, 10 Aug 2006, snacktime wrote:

c = Transaction.new
ProtocolHandler.setcallback {|args| c.Process)

Oops, that should be..

ProtocolHandler.setcallback {|args| c.Process(args)}

Which brings up another question. How would I write a similar block
to handle multiple arguments where the number of arguments isn't known
when I call setcallback?

--
to foster inner awareness, introspection, and reasoning is more efficient than
meditation and prayer.
- h.h. the 14th dali lama

snacktime wrote:

c = Transaction.new
ProtocolHandler.setcallback {|args| c.Process)

Oops, that should be..

ProtocolHandler.setcallback {|args| c.Process(args)}

Which brings up another question. How would I write a similar block
to handle multiple arguments where the number of arguments isn't known
when I call setcallback?

With the 'splat' operator:

ProtocolHandler.setcallback {|*args| c.Process(*args)}

-Justin

ProtocolHandler.setcallback {|*args| c.Process(*args)}

Of course it would be that easy... Thanks!