From: Stefano Crocco Date: 2008-08-17T16:00:54+09:00 Subject: Re: writing if statement in one line with elsif condition On Sunday 17 August 2008, 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! It should work. Look at this: require 'erb' puts "Insert a number" n = gets.to_i str = '<%= if n%3 == 0 then "divisible by three";elsif n%2==0 then "divisible by two";end%>' puts ERB.new(str).result Entering 3 gives "divisible by 3", while entering 2 gives "divisible by two". Stefano