On Sun, Apr 18, 2004 at 07:39:11PM +0900, Robert Klemme wrote:
> 
> "Zsban Ambrus" <ambrus / math.bme.hu> schrieb im Newsbeitrag
> news:20040417194736.GA1309 / math.bme.hu...
> > On Fri, Apr 16, 2004 at 09:23:00AM +0900, nobu.nokada / softhome.net wrote:
> > > Hi,
> > >
> > ..
> > >
> > > I feel Hash#=== would test membership, i.e., alias for
> > > Hash#key?.
> > >
> > > -- 
> > > Nobu Nakada
> >
> > I'd agree with that. This way you could easily test for many possible
> > values in a case statement.
> 
> Does this work?  I mean
> 
> h = {}
> case h
>   when val1, val2
>     ...
> end
> 
> Does something else: it tests val1 === h and val2 === h and not h === val1.
> Currently I don't see how Hash#=== can be used in a case to test for
> multiple values.  In order to use Hash#=== in a case statement, the hash has
> to appear in the when clauses.  Do I overlook something?
> 
> Regards
> 
>     robert
> 
> 

No, I mean something like this:

bad= {};  # bad magic words that the player might try
%w[abracadabra xyzzy hocuspocus bringmehome].each do |x| bad[x]=1 end;
# this list of (bad) magic words might get very long

....

(in a loop)
	....
	gets
	~/^\s*(\w+)/ and word= $1
	case word
	  when bad
	    puts "That won't work in this game.  Nice try, thuogh."
	  when "aardvark" # this is the real magic word
	    player.move(Home)
	  when "a", "ahead"
	    player.move_ahead
	  when "fight", "shoot"
	    (.... check if there's a monster here, kill it with 1/2 probability,
	    otherwise make it angry ...)
	  ....
	end