From: Zach Dennis Date: 2004-08-20T11:54:05+09:00 Subject: Re: Shortest if Assignment Statement a = hsh[val] || hsh['*'] Another beautiful solution for my eyes. Thanks so much David! i am getting so used to the "or" instead of || Zach David A. Black wrote: >Hi -- > >On Fri, 20 Aug 2004, Zach Dennis wrote: > > > >>David A. Black wrote: >> >> >> >>>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. >> >> > >Whoops, I fell into the irb trap :-) > >|| binds more tightly than or, so: > > a = hsh[val] || hsh['*'] > >should give you what you want. > > >David > > >