From: Hugh Sasse Staff Elec Eng Date: 2002-07-10T19:42:30+09:00 Subject: Re: Case expressions and LHS of assignment.... On Wed, 10 Jul 2002, Pit Capitain wrote: > On 10 Jul 2002, at 19:01, Hugh Sasse Staff Elec Eng wrote: > > > On Wed, 10 Jul 2002, Peter Hickman wrote: > > > > You're taking the contrived, cut-down example too literally :-). The > > numbers were easier to type to test this out, I was using symbols in > > fact, :x, :y, and :z in the first place, but the problem is more > > general than that because a case statement can be used with anything > > that copes with ===. > > You can still use a similar approach using a hash with symbols as > keys. In the assignment, use the case expression to detemine the > key. Something like > > def initialize > @values = Hash.new( "Initial" ) > end > > def assign( x, y ) > @values[ > case x > when ... > :x > when ... > :y > else > :z > end > ] = y > end Good point. I like this one. Thank you. > > Regards, > Pit > Hugh