From: Zach Dennis Date: 2004-08-20T11:40:47+09:00 Subject: Re: Shortest if Assignment Statement David A. Black wrote: >Hi -- > >On Fri, 20 Aug 2004, Zach Dennis wrote: > > > >>I am playing with different assignment statements and I am using the >>normal cross-language terinary operator >> >> a = a==1 ? a : -1 >> >>Is there a shorter way to cheat this? I am dealing with a Hash and I >>would like to perhaps do something like: >> >>hsh = { '*' => '(*)' , 'a' => '(1){2}' } >>val = "b" >>a = hsh[ val ] or hsh['*'] #to give me, a = '(*)' >>val = "a" >>a = hsh[ val ] or hsh['*'] #to give me, a = '(1){2}' >> >> > >I'm not quite following. What's not working as you'd like exactly? > > > hsh = { '*' => '(*)' , 'a' => '(1){2}' } val = "b" a = hsh[ val ] or hsh['*'] #to give me, a = '(*)' puts a val = "a" a = hsh[ val ] or hsh['*'] #to give me, a = '(1){2}' puts a I want the fourth line to output (*) instead it gives me nil. Zach