On 10/3/05, James Edward Gray II <james / grayproductions.net> wrote:
> This was quite problematic when I was building my own version.  I
> tried to get around it with my $stringify global, but that requires
> you to spell out all allowed words.

I solved it by letting method_missing fill in the allowed words itself.
The trick is that all the allowed words are used in Game#initialize,
so after the global Game object is constructed, any additional unknown
words must be invalid commands.

class Game
   def initialize
      @objects = [whiskey_bottle, frog, bucket, chain]
  #...
  end
  #...
end

$g = Game.new
$valid_words = []

def method_missing symbol, *args
       #if the game has not started, add the symbol to the list of valid tokens
       if !$g
               $valid_words << symbol
               symbol.to_s
       #if the game has started, see if it is a token
       elsif $words.include? symbol
               symbol.to_s
       #otherwise, it is an unknown command.
       else
               puts "> #{symbol} #{args.join ' '}" if !$Interactive
               puts "Sorry, I don't understand #{symbol}"
       end
end



-Adam