Design help? Mixins and duck-typing

Discussion in 'Ruby' started by Dave Fayram, Aug 27, 2003.

  1. Dave Fayram

    Dave Fayram Guest

    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!

    --
    Dave Fayram

    Developer / Idealist
    --
    Dave Fayram, Aug 27, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    302
    Terry Reedy
    Jan 28, 2008
  2. T. Onoma

    Duck Typing and Object Hashish

    T. Onoma, Nov 12, 2003, in forum: Ruby
    Replies:
    2
    Views:
    95
    dhtapp
    Nov 13, 2003
  3. Raphael Bauduin
    Replies:
    3
    Views:
    97
    Zachary P. Landau
    Nov 18, 2003
  4. Robert Klemme

    Duck Typing and automated Conversions

    Robert Klemme, Jan 14, 2005, in forum: Ruby
    Replies:
    31
    Views:
    290
    Robert Klemme
    Jan 24, 2005
  5. Ola Bini
    Replies:
    1
    Views:
    109
    Austin Ziegler
    Sep 22, 2006
Loading...

Share This Page