From: Paul Brannan Date: 2002-02-20T04:14:11+09:00 Subject: Re: advice on dispatch tables On Wed, Feb 20, 2002 at 04:06:11AM +0900, Matt Armstrong wrote: > Mark Probert writes: > > > @dispatch['a'] = 'do_a' > > @dispatch['b'] = 'do_b' > > I'd use symbols instead of strings here: > > @dispatch['a'] = :do_a > @dispatch['b'] = :do_b Using symbols is definitely faster than using strings. As an alternative, use method() instead: @dispatch['a'] = method(:do_a) @dispatch['b'] = method(:do_b) > if @dispatch[ref] > send @dispatch[ref] > else if meth=@dispatch[ref] then meth.call() end This allows your dispatch table to include anonymous functions (procs) and other objects that respond to call(), in addition to methods. Paul