From: Michael Morin Date: 2008-08-18T07:31:48+09:00 Subject: Re: writing if statement in one line with elsif condition 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! > Ideally, even this rather trivial code is best left outside of ERB files. Hide this away in a function and it can be as clean and multi-liney as you want and doesn't muck up your ERB files. This is doubleplus true if this code is used more than once. Cramming the entire if statement onto line just makes it less readable. -- Michael Morin Guide to Ruby http://ruby.about.com/ Become an About.com Guide: beaguide.about.com About.com is part of the New York Times Company