From: Jason Foreman Date: 2005-05-12T05:07:53+09:00 Subject: Re: alternatives to ? : contruct On 5/11/05, James Edward Gray II wrote: > On May 11, 2005, at 2:37 PM, John-Mason P. Shackelford wrote: > > > I don't believe one can use _else_ with an expression modifier. If we > > try to use an if block in this case, things get ugly fast: > > > > a = if y == x; b; else; c; end > > > > Of course I may be missing something. I need to read more code than > > just my own :s > > The if ... then ... else ... end statements people have been posting > are perfectly legal Ruby. Fire up irb an give them a spin. It's > basically just collapsing an if statement to one line, then capturing > the proper return (since statements return things in Ruby). The > "then" is just a pretty replacement for the ; here. > > Hope that helps. > > James Edward Gray II > > I'd prefer it with less ;'s as well: a = if (y==z): b else c end which works perfectly fine: irb(main):025:0> a = if (1==2): 'foo' else 'bar' end => "bar" I really don't like the idea of having an else/otherwise/whatever operator that allows the results of the statement to be the first and last pieces, and the operators and conditions all squished in the middle. B if A else C doesn't read well to me, and would get confusing I think, whereas if A then B else C is very natural. Jason