From: Sandro Paganotti Date: 2008-05-06T19:20:25+09:00 Subject: Re: I know this code is not very 'ruby' Compressed version :D discount_out = [0,40,100,160][discount_category].to_i On Tue, May 6, 2008 at 9:55 AM, Tim Booher wrote: > This function should work, but when I wrote it, I had the feeling that > there would be a much better way to code this function. In particular, I > don't let creating the discount_out variable. anyone want to give me a > nudge in the right direction? > > def discount(discount_category) > # 0 => no discount > # 1 => friend > # 2 => vet > # 3 => super-vet > case discount_category > when 1 > discount_out = 40 > when 2 > discount_out = 100 > when 3 > discount_out = 160 > else > discount_out = 0 > end > discount_out > end > > best, > > tim > -- > Posted via http://www.ruby-forum.com/. > > -- Go outside! The graphics are amazing!