From: Hugh Sasse Staff Elec Eng Date: 2002-07-10T19:11:41+09:00 Subject: Re: Case expressions and LHS of assignment.... On Wed, 10 Jul 2002, Yukihiro Matsumoto wrote: > Hi, > > In message "Case expressions and LHS of assignment...." > on 02/07/10, Hugh Sasse Staff Elec Eng writes: > > |While trying to avoid Repetition in my code I tried to rewrite a case > |statement, thinking how they can be used on the right hand side of an > |assignment, so I tried the left hand side. It basically came down to > |this: > > Unlike Perl (nor C++), the evaluated result of case statement is the > "value", not the "reference". And I feel this is a good thing. Why not A good thing because it would lead to tangled code, "giving too much rope to for the programmer to hang themselves" etc, or some other reason? > > def assign(x,y) > case x > when 1 > @a = y > when 2 > @b = y > when 3 > @c = y > end > end > That is what I did in the end (well, 'y' was a big expression, so I used a temp var to hold it): t = long_boring_expression case x when :one @a = t and so on. I was just trying to optimise my code in the direction of the Don't Repeat Yourself rule, and wondered how far I could push it. > matz. > Hugh