From: Michael Neumann Date: 2001-08-08T02:23:27+09:00 Subject: [ruby-talk:19300] Re: Speaking of the ternary operator.... David Tillman wrote: > > > >>>>> David Alan Black writes: > > > I seem to remember at one point someone saying that the ternary > > operator might be vanishing from Ruby at some point. It may > > have been over on irc, or in my fevered imagination. I'm not > > sure. > > > Personally I wouldn't miss it, though that's neither here nor > > there. I'm just curious about it. > > > > David > > > -- David Alan Black home: dblack@candle.superlink.net work: > > blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav > > > > It isn't very pretty. However; I do use it quite a bit > to save many lines of if/then/else/end: > > @border = args[1].include?(H_border) ? args[1][H_border] : 0 > @align = args[1].include?(H_align) ? args[1][H_align] : false > @spacing = args[1].include?(H_spacing) ? args[1][H_spacing] : false > @padding = args[1].include?(H_padding) ? args[1][H_padding] : false > @width = args[1].include?(H_width) ? args[1][H_width] : false > @bgcolor = args[1].include?(H_bgcolor) ? args[1][H_bgcolor] : false > @bcolor = args[1].include?(H_bcolor) ? args[1][H_bcolor] : false > @bclight = args[1].include?(H_bclight) ? args[1][H_bclight] : false > @bcdark = args[1].include?(H_bcdark) ? args[1][H_bcdark] : false > @center = args[1].include?(H_center) ? args[1][H_center] : false > @format = args[1].include?(H_format) ? args[1][H_format] : [] Try Hash#fetch(key, default): x = args[1] @border = x.fetch(H_border, 0) @align = x.fetch(H_align, false) ... Even shorter than Scheme. Regards, Michael -- Michael Neumann merlin.zwo InfoDesign GmbH http://www.merlin-zwo.de