Design help? Mixins and duck-typing

D

Dave Fayram

Hi folks,
My understanding of proper Ruby and duck-typing idoms is still pretty raw, so I
decided to ask you folks for help.

I'm making a binding to libpcap and libnet for Ruby, which will allow you to do
non-time-critical network traffic analysis in Ruby. Part of my design was that
Packet representations will "mix in" their protocols. For instance, a packet
could be of many different protocols, but still be an IP packet (TCP, UDP,
custom protocol). Likewise, a packet could be a TCP or UDP packet, but not be
transmitted via IP. To me, this seems to be an ideal case for mix-ins.

However, this brings up the problem. Sometimes, people will want to know what
kind of packet a relatively broad filter is spitting back. Is it TCP or UDP? Is
it IP or ICMP? My first instinct was to just let them check the inclusion
history. However, recent reading has revealed to me that relying on the class
and inheritance hierarchy is not the best way to go about doing things in Ruby,
since things are so dynamic.

What then is the right way to let users of the library I am writing check packet
type? A method to include symbols seems to me to be a duplication of
information, which should be avoided. I suppose is_tcp? and is_ip? would be
viable, but seems inelegant to me.

Am I just being picky, or what? Any suggestions are welcome. Thanks for your
time!
 

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
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top