Ross Bamford wrote:
> On Thu, 2006-02-02 at 09:57 +0900, Michael Judge wrote:
> 
>>     1. Storing executable code in the database is a security problem
>>     2. instance_eval is slow
>>     3. The alternative (a big if/elsif tree) would span many pages and 
>> be unweildy.
>> 
>> Have a better suggestion?
> 
> Not necessarily better, but how about something like:
> 
> 	class Commands
>         [snip]
> 	  def dispatch(line)
> 	    if line =~ /([QXM])-?(.*)/
> 	      send($1.intern, $2)
> 	    else
> 	      raise "Invalid input: #{line}"
> 	    end
> 	  end
> 	end

That's neat, Ross.  I wasn't familiar with the send command.  Looks like 
the consequence is that the grammar has to fit an easy regular 
expression or you'd be duplicating it in the match and again in the 
method definition... Well, that's not necessarily a bad thing. 
Consistency is good too.

I need to think about this.

What do programmers normally do when they have a case statement that's 
30 or more items long?  Previously I've just left it as a case statement 
and spent the life of the project ticked at it.

-- 
Posted via http://www.ruby-forum.com/.