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?

On Thu, 10 Aug 2006, snacktime wrote:

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

-a

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!

snacktime wrote:

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

Just a question: why is #Process capitalized?

Cheers,
Daniel

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs