application design advice

S

snacktime

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

snacktime

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

ara.t.howard

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?

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

-a
 
J

Justin Collins

snacktime said:
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
 

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

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,687
Latest member
IngridXxj

Latest Threads

Top