From: Rich Kilmer Date: 2002-02-20T04:16:02+09:00 Subject: RE: advice on dispatch tables > -----Original Message----- > From: Mark Probert [mailto:probertm@nortelnetworks.com] > Sent: Tuesday, February 19, 2002 1:54 PM > To: ruby-talk ML > Subject: advice on dispatch tables > > > > > > (In the "real" version, the hash is more complicated > and there is processing to be done on the 'ref', but > the basic idea is here.) > > Is there a "better" way of doing this? A more > ruby-ish way? > > class Bob def initialize @dispatch = {'a' => :do_a, 'b' => :do_b} end def do_a puts "--> this is an a" end def do_b puts "--> this is an b" end def dispatch(ref=nil) raise "Unknown ref #{ref}" unless @dispatch.key? ref send @dispatch[ref] end end