From: Robert Klemme Date: 2008-08-17T20:06:51+09:00 Subject: Re: writing if statement in one line with elsif condition On 17.08.2008 05:09, Luiz Vitor Martinez Cardoso wrote: > I'm trying to convert it: > > <% if @recipes.length == (i+1) %> > <% @id = 0 %> > <% elsif i.remainder(2) == 1 %> > <% @id = 1 %> > <% else %> > <% @id = 2 %> > <% end %> > > To something like: > > <% if @recipes.length == (i+1) then @id = 0 ; elsif > i.remainder(2) == 1 then @id = 1 ; else @id = 2 end >% > > But in my tests the elsif condition is totally ignored, why? > > Thanks for you attention! Agreeing with the others: it's probably your expectation about the first condition which is wrong. Btw, here's another way to do it @id = case when @recipes.length == i + 1: 0; when i.remainder(2) == 1: 1; else 2 end Although I admit that I'd rather have it on several lines @id = case when @recipes.length == i + 1: 0 when i.remainder(2) == 1: 1 else 2 end Kind regards robert