From: Mark Probert Date: 2002-02-20T03:54:23+09:00 Subject: advice on dispatch tables I am playing around with using a dispatch table rather than a huge case statement. I end up with code that looks something like this: class Bob def initialize @dispatch = Hash.new @dispatch['a'] = 'do_a' @dispatch['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) if @dispatch[ref] eval @dispatch[ref] else puts "--> unknown ref (#{ref})" end end end (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? Thanks for the feedback. -mark.